如何组合“|” powerbuilder 中 run () 命令中的字符以便读取 txt 文件作为文件(pdf)的元数据输出?
您能否告诉我如何在 powerbuilder run 命令中使用“pdftk mypdf.pdf dump data | findstr NumberOfPages 并使用以下代码将此元数据保存在文件中,如下所示:
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!)
问题是执行了 Run 命令,创建了文件,但是 fileopen 返回 -1 ? 是不是run无法识别“|”?特点? 您应该建议我怎样编写正确的代码? 我正在使用 powerbuilder 10.5.2 ,非常感谢
Could you please tell me how to use "pdftk mypdf.pdf dump data | findstr NumberOfPages in powerbuilder run command and save this metadata in a file by using the following code like this:
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 Run command is executed, the file is created, but fileopen return -1 ?
Is it maybe that run cannot recognize the "|" character?
What should you propose me to write the right code?
Iam using powerbuilder 10.5.2 , Thanks very much in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Powerbuilder 不会等待
Run()
调用的过程完成。Run()
的返回值仅基于其是否成功调用外部进程,而不基于外部进程接下来执行的操作。这意味着 pdftk 很可能已正确完成,但您尝试过早访问输出。当它完成后,你必须找到一些锻炼的方法。也许从批处理文件中调用它,该批处理文件在完成之前创建另一个文件,然后在 Powerbuilder 中检查该文件是否存在。
或者,您可以使用不同的方法来调用外部流程。这是通过 Windows 脚本主机调用外部进程的示例:(
代码示例摘自 Stuart多尔比的网站)。
如果您仍然无法使其工作,最好的办法是将其拆分出来,并验证您是否可以首先对预先存在的文件执行
FileOpen
,然后在外部验证该过程的输出由Run()
调用是正确的(最终)。仅供参考,
|
字符不是特殊字符,不需要在字符串中转义。Powerbuilder does not wait for the process called by
Run()
to complete. The return values ofRun()
are based solely on whether it successfully called the external process, not on what the external process did next.This means that pdftk has most likely completed correctly, but you tried to access the output too soon. You'll have to find some way of working out when it has completed. Maybe call it from a batch file that creates another file before it completes, and then in Powerbuilder check for the existance of that file.
Alternatively, you can use a different method of calling your external process. This is an example of calling an external process via Windows Scripting Host:
(code example cribbed from Stuart Dalby's site).
If you still can't get it working, your best bit is to split it out, and verify that you can do a
FileOpen
on pre-existing file first, then verify externally that the output of the process called byRun()
is correct (eventually).Just for reference, the
|
character is not a special character and does not need escaping in a string.Roland Smith 在他的网站上有一个用于运行和等待的库和示例,可以满足您的需要:
http: //www.topwizprogramming.com/freecode_runandwait.html
还有其他变体可以做类似的事情(我们从某个地方获取了一个名为 uo_syncproc 的对象,该对象使用各种 Windows 函数来执行此操作(CreateProcessA、WaitForSingleObject、CloseHandle)。
Roland Smith has a library and example for doing Run and Wait on his website that may do what you need:
http://www.topwizprogramming.com/freecode_runandwait.html
There are other variations out there that do similar things (we acquired an object called uo_syncproc from somewhere that uses various windows functions to do this (CreateProcessA, WaitForSingleObject, CloseHandle).