如何获得外部程序(ARJ)的返回参数? (100分)

  • 主题发起人 主题发起人 fanglw
  • 开始时间 开始时间
F

fanglw

Unregistered / Unconfirmed
GUEST, unregistred user!
我想通过调用外部程序ARJ来对数据进行压缩和解压缩,但是不知道怎样得到程序运行时返<br>回的参数,如:磁盘的空间是否够用,是否需要换盘等等,并且要根据状态对该外部程序<br>作出处理,不知该如何实现?
 
param(1)不行吗?
 
这应该是无法实现的,除非ARJ在执行时有返回参数,不过好象不可能
 
好像可以实现,<br>BOOL GetExitCodeProcess(<br>&nbsp; HANDLE hProcess, &nbsp; &nbsp; // handle to the process<br>&nbsp; LPDWORD lpExitCode &nbsp; // termination status<br>);<br>你使用 createprocess 获得的 handle 可以用来获得返回值。
 
好象是可以的,96年左右的《微型计算机应用》上有一篇文章,是利用Borland C++本身的<br>编辑器(DOS下的只用于纯文本)为Clipper(一种编译型的Dbase)开发一个集成环境,Clipper<br>本身是一个命令行的编译器,可能有多种输出信息(如出错信息等),该文章利用了输入重定向的方法。<br>首先:将编辑器编辑器的文件存盘,文件作为参数传给Clipper,<br>其次:调用Clipper,并将Clipper输出的信息重定向到一个文本文件中,<br>再次:程序监视这个文件,只要一有输入,就将东西显示在编辑器的信息窗中。<br>最后:对出错信息作相应的处理,如出错行定位等。<br>当年看了很感兴趣,想为当时的MS fortran开发一个集成环境,但只是想想而已,没有作。<br>95年前后,还有一个软件叫Winarj(不是现在的那种),它是DOS ARJ在Win3.2下的一个外壳<br>它在Windows下为Arj形成命令行参数,如分卷等,调用DOS的ARJ,把相关提示在Windows下显示出来。<br>这个软件在电脑报配套光盘第一期上有。<br>说这些只是想为你提供一个思路,文章我有,只是不知道还找不找得到。<br>我想如果不是特别要求,就不要用Dos下的ARJ了,必竟现在的压缩控件到处都是,随便找一<br>个都比ARJ好用,而且发布也方便。现在在来钻研DOS下的东东,有点......
 
用zipTV或VCLZIP、ZIPOCX......吧!
 
还记得这样吗?<br><br>arj a abc c:/windows/command/*.* -r &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &gt; a.txt<br><br>然后对这个a.txt做处理吧
 
从Dev C++源代码中Copy出来的例程:<br><br>function RunFile_(Cmd, WorkDir : string; Wait : boolean) : Boolean;<br>var<br>&nbsp; tsi: TStartupInfo;<br>&nbsp; tpi: TProcessInformation;<br>&nbsp; nRead: DWORD;<br>&nbsp; aBuf: Array[0..101] of char;<br>&nbsp; sa: TSecurityAttributes;<br>&nbsp; hOutputReadTmp, hOutputRead, hOutputWrite, hInputWriteTmp, hInputRead,<br>&nbsp; hInputWrite, hErrorWrite: THandle;<br>&nbsp; FOutput: String;<br>begin<br>&nbsp; FOutput := '';<br><br>&nbsp; sa.nLength &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= SizeOf(TSecurityAttributes);<br>&nbsp; sa.lpSecurityDescriptor := nil;<br>&nbsp; sa.bInheritHandle &nbsp; &nbsp; &nbsp; := True;<br><br>&nbsp; CreatePipe(hOutputReadTmp, hOutputWrite, @sa, 0);<br>&nbsp; DuplicateHandle(GetCurrentProcess(), hOutputWrite, GetCurrentProcess(),<br>&nbsp; &nbsp; @hErrorWrite, 0, true, DUPLICATE_SAME_ACCESS);<br>&nbsp; CreatePipe(hInputRead, hInputWriteTmp, @sa, 0);<br><br>&nbsp; // Create new output read handle and the input write handle. Set<br>&nbsp; // the inheritance properties to FALSE. Otherwise, the child inherits<br>&nbsp; // the these handles; resulting in non-closeable handles to the pipes<br>&nbsp; // being created.<br>&nbsp; DuplicateHandle(GetCurrentProcess(), hOutputReadTmp, &nbsp;GetCurrentProcess(),<br>&nbsp; &nbsp; @hOutputRead, &nbsp;0, false, DUPLICATE_SAME_ACCESS);<br>&nbsp; DuplicateHandle(GetCurrentProcess(), hInputWriteTmp, GetCurrentProcess(),<br>&nbsp; &nbsp; @hInputWrite, 0, false, DUPLICATE_SAME_ACCESS);<br>&nbsp; CloseHandle(hOutputReadTmp);<br>&nbsp; CloseHandle(hInputWriteTmp);<br><br>&nbsp; FillChar(tsi, SizeOf(TStartupInfo), 0);<br>&nbsp; tsi.cb &nbsp; &nbsp; &nbsp; &nbsp; := SizeOf(TStartupInfo);<br>&nbsp; tsi.dwFlags &nbsp; &nbsp;:= STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;<br>&nbsp; tsi.hStdInput &nbsp;:= hInputRead;<br>&nbsp; tsi.hStdOutput := hOutputWrite;<br>&nbsp; tsi.hStdError &nbsp;:= hErrorWrite;<br>&nbsp; tsi.wShowWindow := SW_SHOW;<br><br>&nbsp; CreateProcess(nil, PChar(Cmd), @sa, @sa, true, 0, nil, PChar(WorkDir),<br>&nbsp; &nbsp; tsi, tpi);<br>&nbsp; CloseHandle(hOutputWrite);<br>&nbsp; CloseHandle(hInputRead );<br>&nbsp; CloseHandle(hErrorWrite);<br>&nbsp; Application.ProcessMessages;<br><br>&nbsp; if Wait then<br>&nbsp; repeat<br>&nbsp; &nbsp; &nbsp;if (not ReadFile(hOutputRead, aBuf, 16, nRead, nil)) or (nRead = 0) then<br>&nbsp; &nbsp; &nbsp;begin &nbsp;//命令行的输出被读到 aBuf 中了<br>&nbsp; &nbsp; &nbsp; &nbsp; if GetLastError = ERROR_BROKEN_PIPE then Break<br>&nbsp; &nbsp; &nbsp; &nbsp; else MessageDlg('Pipe read error, could not execute file', mtError, [mbOK], 0);<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;aBuf[nRead] := #0;<br>&nbsp; &nbsp; &nbsp;FOutput := FOutput + PChar(@aBuf[0]);<br>&nbsp; &nbsp; &nbsp;Application.ProcessMessages;<br>&nbsp; until False;<br><br>&nbsp; Result := GetExitCodeProcess(tpi.hProcess, nRead) = True;<br>end;<br>&nbsp; 具体的工作原理我也不太清楚,好象关键是利用管道。Dev C++ 中使用了类似的例程调用<br>外部的 Mingw C/C++ 命令行编译器对C/C++程序进行编译。推荐你到 www.bloodshed.net去<br>下载它的Delphi源程序,是基于GPL开放源码的。
 
接受答案了.
 
后退
顶部