How to combine "|" character in run () command in powerbuilder to read txt file as file metadata (pdf) output?

Could you tell me how to use "dump data" pdftk mypdf.pdf | findstr NumberOfPages in the powerbuilder startup command and save this metadata to a file using the following code:

string ls_runinput, ls_outputfile ls_outputfile = "c:\test.txt" ls_runinput = "c:\pdftk\pdftk.exe mypdf.pdf dump_data | findstr NumberOfPages >"+ls_outputfile Run(ls_runinput,Minimized!) li_fileopen = FileOpen(ls_outputfile ,TextMode!, Read!, Shared!) 

The problem is that the Run command is executed, the file is created, but fileopen returns -1? Perhaps this run cannot recognize "|" the character? What should you suggest me write the correct code? Iam using powerbuilder 10.5.2, thanks in advance

+4
source share
2 answers

Powerbuilder does not wait for the process called by Run() . The return values โ€‹โ€‹of Run() are based solely on whether it successfully called the external process, and not on what the next external process did.

This means that pdftk most likely completed correctly, but you tried to get the exit too quickly. You will need to find some kind of development method when it is complete. Perhaps call it from a batch file that creates another file before it is completed, and then in Powerbuilder will check for the presence of this file.

Alternatively, you can use another method to call an external process. This is an example of invoking an external process using the Windows Scripting Host:

 OleObject wsh CONSTANT integer MAXIMIZED = 3 CONSTANT integer MINIMIZED = 2 CONSTANT integer NORMAL = 1 CONSTANT integer HIDE = 0 CONSTANT boolean WAIT = TRUE CONSTANT boolean NOWAIT = FALSE wsh = CREATE OleObject li_rc = wsh.ConnectToNewObject( "WScript.Shell" ) li_rc = wsh.Run(ls_runinput, HIDE, TRUE) 

(sample code cut from Stuart Dalby's website ).

If you still can't get it to work, your best bit is to break it down and make sure you can first make FileOpen in a pre-existing file, and then check externally that the output of the process called Run() is correct ( ultimately).

Just for reference symbol | It is not a special character and does not need to be escaped in a string.

+3
source

Roland Smith has a library and an example to run Run and Wait on his website, which can do what you need:

http://www.topwizprogramming.com/freecode_runandwait.html

There are other options that do similar things (we got an object called uo_syncproc, somewhere that uses various windows functions to do this (CreateProcessA, WaitForSingleObject, CloseHandle).

+1
source

Source: https://habr.com/ru/post/1305652/


All Articles