如何通过我的windows程序控制一个正在运行的DOS程序的参数输入?200分征求源代码(200分)

G

guodemo

Unregistered / Unconfirmed
GUEST, unregistred user!
本人现在写好了一个windows程序,假设有另一个DOS下的程序我要运行,<br>而且这个DOS程序在运行中要用户输入几个参数,我如何将用户在我的<br>Windows程序中填入的参数传递个正在运行的这个DOS程序,让DOS程序<br>继续执行直至结束???希望高手给予执教,我愿用用尽我所有的200<br>分......最好有SourceCode......急、急、急!!!
 
1。这个DOS程序是不是你写的?<br>2。你的意思是不是在WINDOWS界面下用户输入数据,然后由WINDOWS程序传给DOS程序处理?<br>3。实时性如何?
 
我的办法:提思路<br>假定你的DOS文件是ABC.EXE<br>用DOS的重定向给DOS命令传递参数。例如你的DOS执行文件中要输入'somechar'<br>,你首先把这个字符写到一个文本文件中去如para.txt,这DELPH中控件不难。然后在<br>你首先在DOS下试试  abc.exe &lt;para.txt 如果这执行正确的话就有办法了。<br><br>你在调用这个文件之前先确定你的参数是什么,然后将参数写到一个文本文件中去。<br>然后用winexec调用DOS命令<br>Winexec(pchar('command.com /c abc.exe &lt;para.txt'),sw_hide);<br><br>
 
先运行command或cmd然后再在cmd中启动那个程序,再....<br>我的有一个程序外壳就是这样做的, 就是老李版虚拟光驱. 呵呵.
 
谢谢朋友们给我回贴,我还要注释一下:dos程序不是我写的,dos程序运行是会提示输入<br>密码,如果手动运行时,输入密码当时它的光标是不会动的,我想也许是用C中Getkey这样<br>的参数获取输入的密码,我试验过管道好像没有效果,因为dos程序输入密码时不是获取输<br>入密码的整个字串。
 
请问一下,<br>1、你是想用WINDOW的程序去调用一个DOS的程序,还是此DOS程序已经运行,而后,<br>你的WINDOWS程序才运行?<br>2、你的DOS程序的参数是在运行刚开始就已经全部输入了,还是在DOS程序运行的过程当中<br>还需要输入参数?<br>
 
是用windows运行dos程序,然后在dos程序运行的时候要求把我的程序中Edit中用户输入<br>的密码实时传到dos程序中,引导dos程序执行!
 
function WinExecAndWait32(FileName, Params: string;<br>&nbsp; ShowRunForm: Boolean = True): integer;<br>var<br>&nbsp; zAppName: array [0..512] of char;<br>&nbsp; zCurDir: array [0..255] of char;<br>&nbsp; CurDir, WorkDir: string;<br>&nbsp; dwExitCode: DWord;<br>&nbsp; StartupInfo: TStartupInfo;<br>&nbsp; ProcessInfo: TProcessInformation;<br>begin<br>&nbsp; Result := 0;<br>&nbsp; WorkDir := ExtractFilePath(FileName);<br>&nbsp; FileName := FileName + ' ' + Params<br>&nbsp; StrPCopy(zAppName, FileName);<br>&nbsp; GetDir(0, CurDir);<br>&nbsp; StrPCopy(zCurDir, CurDir);<br>&nbsp; dwExitCode := STILL_ACTIVE;<br>&nbsp; FillChar(StartupInfo, Sizeof(TStartupInfo), #0);<br>&nbsp; FillChar(ProcessInfo, SizeOf(TProcessInformation), #0);<br>&nbsp; StartupInfo.cb := Sizeof(StartupInfo);<br>&nbsp; StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; if ShowRunForm then<br>&nbsp; &nbsp; StartupInfo.wShowWindow := sw_Normal // 显示 DOS 窗口<br>&nbsp; else<br>&nbsp; &nbsp; StartupInfo.wShowWindow := sw_Hide; // 不显示 DOS 窗口<br>&nbsp; if not CreateProcess(<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //待执行程序名<br>&nbsp; &nbsp; zAppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//执行参数<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //进程安全级别<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //线程安全级别<br>&nbsp; &nbsp; false, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //继承标志<br>&nbsp; &nbsp; DETACHED_PROCESS + &nbsp; &nbsp; //创建标志<br>&nbsp; &nbsp; HIGH_PRIORITY_CLASS,<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //环境变量,如:"Files=20;"<br>&nbsp; &nbsp; Pointer(WorkDir), &nbsp; &nbsp; &nbsp;//当前路径<br>&nbsp; &nbsp; StartupInfo, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //STARTUPINFO 纪录信息<br>&nbsp; &nbsp; ProcessInfo) then Result := 0 &nbsp;//PROCESS_INF 纪录信息<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;if ProcessInfo.hProcess &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; while (dwExitCode = STILL_ACTIVE) do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; WaitForSingleObject(ProcessInfo.hProcess, 50);<br>&nbsp; &nbsp; &nbsp; &nbsp; GetExitCodeProcess(ProcessInfo.hProcess, dwExitCode);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>调用:(假设要调用的程序为 FileNameEdt, 要传的参数放在 ParamEdt1, ParamEdt2)<br><br>&nbsp; WinExecAndWait32(FileNameEdt.Text, ParamEdt1.Text + ' ' + ParamEdt2.Text);<br>&nbsp; ShowMessage('调用完成');<br><br>
 
To:beta<br>&nbsp; &nbsp;很好,不过,如果该Dos程序如果还有返回值,如:ping 192.168.0.1<br>&nbsp; &nbsp;等.....
 
问题问得不得要领,sentiment想知道你的DOS程序先运行还是你的EDIT程序先运行
 
对不起,是先运行我的Delphi程序,再dos程序
 
楼主的意思应该是做一个类似Cmd.exe的东西<br>beta的代码能做到运行一个程序并等待其退出再返回你的程序<br>现在还剩下两个问题,一是如何把在Edit框输入的字符串发送给正在运行的Dos程序<br>一是怎么返回运行结果。<br>前者,你可以查MSDN实现,查“AllocConsole”然后通过<br>“Consoles and Character-Mode Support Overview”取得更多信息。<br>后者可以通过PIPE实现,如果没记错的话,我以前在论坛贴过代码,你找找看。
 
我试过PIPE但是没有用处,dos程序根本收不到信息。我也试过SendKey,也不行!
 
用PIPE就全部搞定了<br>我可以发DEMO给你,EMAIL?
 
我的Mail是guodemo@hotmail.com
 
我也要,SENTIMENT@263.NET
 
楼主说管道&lt;不起作用。<br><br>我想到一个命令<br>TYPE A.TXT|A.EXE<br>试试<br><br>虽然不合楼主的要求,不妨试试
 
顶部