>>>
>I use API_APPRUN class to run pg_dump.exe file
>>>>
>>>>I need to show the messages from it after it finishes.
>>>>
>>>>How to capture standard output and redirect it to file ?>>>
>>>How about?
>>>
>>>
pg_dump.exe > log.txt
>>>
>>>then you inspect log.txt?
>>
>>And in case we need to capture stderr as well, here's a neat trick I already forgot twice, and had to google it out again:
>>
>>
pg_dump.exe > log.txt 2>err.txt
>
>Thank you.
>I forget to mention that I need need also:
>
>1. Pass PGPASSWORD= environment variable to pg_dump (this seems to be the only way to pass password to pg_dump non-interactively). I modified APP_APPRUN to allow passing environment variables.
>
>2. Capture exit code returned by pg_dump.exe to know that backup was completed OK.
>
>How to implement those features ?
To set an environment variable, you should wrap your call in a batch file:
text to lcBatText textmerge noshow
set pgpassword=<<lcPass>>
"<<fullpath("pg_dump.exe")>>"
endtext
lcHere=fullpath(set("directory"))
lcBat=fullpath("tmp.bat")
strtofile(lcBatText, lcBat)
oprocess=Newobject('api_apprun','process', '', lcbat, lcHere, 'HID')
oprocess.LaunchAppAndWait()
To check the exit code (I presume that's same as ErrorLevel), you can try to use oProcess.CheckProcessExitCode(nHandle). There's no actual example in the class itself, but you can tweak the class code to add a line which would assign this exitcode into a custom property of oProcess before exiting.
The trouble here is that with the batch file, the batch is your process, not the exe, so you may get perfect zeros all the time. If you managed to set the environment variable without a batch file, you can then run CheckProcessExitCode() before you kill oProcess and retrieve the exit code. If you need to use the batch, it's then as simple as adding another line to the batch:
text to lcBatText textmerge noshow
set pgpassword=<<lcPass>>
"<<fullpath("pg_dump.exe")>>"
echo %errorlevel% >errorlevel.txt
endtext
And then you just use
nErrorLevel=val(filetostr("errorlevel.txt"))
to get its value.