As you can read in the help of ReadProgramError() it does not stop the code when you call it.
The example above is not correct.
You should place it outside of the If Available statement.
And check if the result is an empty string before you concat it to the real output string.
It would be much easier if you provided a link where we can download this program if it is freeware.
Im not spending time to search such stuff to help.
Can not to read program console output :(
Re: Can not to read program console output :(
https://sedutil.com
https://github.com/ChubbyAnt/sedutil/releases
sedutil-cli.exe-1.15-5ad84d8.zip
128 KB
06 Jan 2021
Need to be launch with admin rights
@dibor
- There is many think to know when using CMD (/C /K etc) with special char (like | >), see CMD /?
- I don't know if #PB_Program_Read | #PB_Program_Error intercept Output first, so 2>&1 can perhaps receive nothing ? (except using some tool like TEE (if exist in Windows)) (not tested)
Edit: Running your first code and set compiler option ADMIN RIGHTS and that works
https://github.com/ChubbyAnt/sedutil/releases
sedutil-cli.exe-1.15-5ad84d8.zip
128 KB
06 Jan 2021
Need to be launch with admin rights
Code: Select all
C:\>sedutil-cli.exe --scan
Scanning for Opal compliant disks
\\.\PhysicalDrive0 No
\\.\PhysicalDrive1 No
\\.\PhysicalDrive2 No XXXXXXXXXXXXXXXXXXXX XXXXXXXX
\\.\PhysicalDrive3 No XXXXXXXXXXXXXXXXXXXX XXXXXXXX
No more disks present ending scan
- There is many think to know when using CMD (/C /K etc) with special char (like | >), see CMD /?
- I don't know if #PB_Program_Read | #PB_Program_Error intercept Output first, so 2>&1 can perhaps receive nothing ? (except using some tool like TEE (if exist in Windows)) (not tested)
Edit: Running your first code and set compiler option ADMIN RIGHTS and that works
Last edited by Marc56us on Thu Jun 30, 2022 8:40 am, edited 1 time in total.
-
- Enthusiast
- Posts: 125
- Joined: Wed May 20, 2020 5:19 pm
- Location: The 3rd planet in the Solar System
- Contact:
Re: Can not to read program console output :(
Help about ReadProgramError says - Reads a line from the specified programs error output (stderr).
I do not know if this correct or not.
For example.
With this:
I got error "method status code NOT_AUTHORIZED"
And with cmd /c
Got error output:
method status code NOT_AUTHORIZED
Session start failed rc = 1
One or more header fields have 0 length
EndSession Failed
I do not know if this correct or not.
For example.
With this:
Code: Select all
Program = RunProgram ("sedutil-cli.exe", "--yesIreallywanttoERASEALLmydatausingthePSID 235325 \\.\PhysicalDrive2", "", #PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
And with cmd /c
Code: Select all
Program = RunProgram("cmd.exe", "/c sedutil-cli.exe --yesIreallywanttoERASEALLmydatausingthePSID 235325 \\.\PhysicalDrive2 2>&1", "", #PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
method status code NOT_AUTHORIZED
Session start failed rc = 1
One or more header fields have 0 length
EndSession Failed
Mac Studio M1Max, PB 6.03Arm64 and x64.
Macbook Air M2, PB 6.03Arm64 and x64.
Windows 10, PB 6.03 x64 and x86.
Macbook Air M2, PB 6.03Arm64 and x64.
Windows 10, PB 6.03 x64 and x86.
Re: Can not to read program console output :(
I just tested your first code by setting the admin mode in the compiler options and it works.
[X] Enable Administrator mode for Windows Vista and above
This is logical, since if you launch the tool from the command line in a standar console, it asks you to restart the console in admin mode.
Edit: Oops, yeah, I hadn't reread all the answers. The administrator mode has already been mentioned on the previous page. Sorry about that.
[X] Enable Administrator mode for Windows Vista and above
This is logical, since if you launch the tool from the command line in a standar console, it asks you to restart the console in admin mode.
Code: Select all
SetCurrentDirectory("C:\Tmp")
Program = RunProgram ("sedutil-cli.exe", " --scan", "",
#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
Debug "Program is " + Program
String$ = ""
If Program
While ProgramRunning(Program)
If AvailableProgramOutput(Program)
String$ = String$ + ReadProgramString(Program) + Chr(13)
EndIf
Wend
String$ + "Exitcode: " + Str(ProgramExitCode(Program))
CloseProgram(Program) ; Close the connection to the program
Debug "Out is : " + String$
EndIf
Code: Select all
Program is 7146576
Out is :
Scanning for Opal compliant disks
\\.\PhysicalDrive0 No
\\.\PhysicalDrive1 No
\\.\PhysicalDrive2 No XXXXXXXXXXXXXXXXXXXX XXXXXXXX
\\.\PhysicalDrive3 No XXXXXXXXXXXXXXXXXXXX XXXXXXXX
No more disks present ending scan
Exitcode: 0
Edit: Oops, yeah, I hadn't reread all the answers. The administrator mode has already been mentioned on the previous page. Sorry about that.
Last edited by Marc56us on Thu Jun 30, 2022 10:25 am, edited 1 time in total.
-
- Enthusiast
- Posts: 125
- Joined: Wed May 20, 2020 5:19 pm
- Location: The 3rd planet in the Solar System
- Contact:
Re: Can not to read program console output :(
Hi.
Thanks, yes this code is works.
Now doesnt works multi line error output
Mac Studio M1Max, PB 6.03Arm64 and x64.
Macbook Air M2, PB 6.03Arm64 and x64.
Windows 10, PB 6.03 x64 and x86.
Macbook Air M2, PB 6.03Arm64 and x64.
Windows 10, PB 6.03 x64 and x86.
Re: Can not to read program console output :(
Hello,
Sorry for my absence.
Here is a method that works by generating 2 files, one for standard output, the other for error output.Comment one of the 2 param$ lines to test the result.
If an error occurs, then fileErr$ contains the errors.
Otherwise the file fileStd$ contains the result of the command.
cage
Sorry for my absence.
Here is a method that works by generating 2 files, one for standard output, the other for error output.
Code: Select all
fileErr$="test-err.log"
fileStd$="test-std.log"
param$="/c sedutil-cli.exe --scan 2>"+fileErr$+" 1>"+fileStd$
param$="/c sedutil-cli.exe --yesIreallywanttoERASEALLmydatausingthePSID 235325 \\.\PhysicalDrive0 2>"+fileErr$+" 1>"+fileStd$
Program = RunProgram ("cmd.exe",param$,#Empty$,#PB_Program_Wait|#PB_Program_Hide)
If an error occurs, then fileErr$ contains the errors.
Otherwise the file fileStd$ contains the result of the command.
cage
■ Win10 64-bit (Intel Celeron CPU N2920 @ 1.86GHz, 4,0GB RAM, Intel HD Graphics) & PB 6.00 LTS
■ Vivre et laisser vivre.
■ PureBasic pour le fun
■ cage sur le forum Français
■ Mes sites: http://pbcage.free.fr - http://yh.toolbox.free.fr
■ Vivre et laisser vivre.
■ PureBasic pour le fun
■ cage sur le forum Français
■ Mes sites: http://pbcage.free.fr - http://yh.toolbox.free.fr
-
- Enthusiast
- Posts: 125
- Joined: Wed May 20, 2020 5:19 pm
- Location: The 3rd planet in the Solar System
- Contact:
Re: Can not to read program console output :(
Thank you Gérard for your time.
With cmd.exe /c multi line error output is works.
But doesn't when used direct command , like :
Anyway, cmd.exe /c method is works and I am going to use it.
Thanks to ALL!!
PS Looks like problem exists only when I sent error output to the string.
If I send to the status bar I see different output.
With cmd.exe /c multi line error output is works.
But doesn't when used direct command , like :
Code: Select all
Program = RunProgram ("sedutil-cli.exe", "--yesIreallywanttoERASEALLmydatausingthePSID 235325 \\.\PhysicalDrive2", "", #PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
Thanks to ALL!!
PS Looks like problem exists only when I sent error output to the string.
If I send to the status bar I see different output.
Mac Studio M1Max, PB 6.03Arm64 and x64.
Macbook Air M2, PB 6.03Arm64 and x64.
Windows 10, PB 6.03 x64 and x86.
Macbook Air M2, PB 6.03Arm64 and x64.
Windows 10, PB 6.03 x64 and x86.