如何获得由 'FOR1.EXE' 检查所得的有关信息?(100分)

  • 主题发起人 主题发起人 Jamson
  • 开始时间 开始时间
J

Jamson

Unregistered / Unconfirmed
GUEST, unregistred user!
先生:<br>&nbsp; &nbsp; 不知道您还记得微软的‘Fortran 77 ’否? 这是个纯DOS版本的Fortran编译器,我打算为其做一个SHELL。在这个SHELL中,我需要后台运行其中的<br>FOR1.EXE,运行的命令格式(在DOS下)为:‘for1 name.for;’。我尝试<br>实现DOS中的‘for1 name.for;&gt;&gt;try.txt ’,希望能将有关检查信息置<br>于文件‘try.txt’中。于是用‘ name.for;&gt;&gt;try.txt’用作ShellExecute中‘for1.exe’的运行参数,但结果‘for1.exe’报错且不接‘&gt;&gt;try.txt’<br>为参数,但此命令行在DOS下运行正常。为此请教先生如何获得‘for1.exe’检查所得到的信息?
 
在DOS中,“&gt;&gt;”是做为输出管道,<br>而在一般的程序中的参数,是做为程序的输入部分<br>虽然我并不知道你所做SHELL的用意,但我想你可以在程序中以外部程序的方式调用,<br>而不要作为参数进行输入
 
DOS下屏幕的输出,即con也是有某个固定的文件句柄的,<br>&nbsp; &nbsp; 应该是1-5之间的某个数,<br>就是说,屏幕输出也就是往con写文本就是了,<br>你设置你的文件如try.txt的打开句柄为con的句柄就是了。<br><br>另外,如象forshell已经有了吧?
 
使用For1 文件名.for &gt;&gt;文件名<br>不会有问题。
 
用下列方式ShellExecute<br>'COMMAND.COM /C C:/test/for1 name.for; &gt;&gt; C:/test/try.txt'
 
'COMMAND.COM /C C:/test/for1.exe name.for &gt;&gt; C:/test/try.txt'
 
SEASKY的方法肯定行, 必须指明全路径才行.<br>c:/COMMAND.COM /C C:/test/for1.exe C:/test/name.for &gt;&gt; C:/test/try.txt<br>
 
win95下用bat方式进行stdout重定向,可能并不是这么简单,请看以下M$用VB给的例子:<br><br>After the parent Visual Basic application spawns the child console process, the parent Visual Basic application provides input to the child's STDIN and receives the output from the child's STDOUT. By using a batch file, the parent Visual Basic application provides the child's STDIN through a disk file and collects the child's STDOUT through another disk file. <br><br><br>Step-by-Step Example<br>Create a console application, CONSOL.EXE, that expects an integer as its STDIN and sends a text string out as its STDOUT, using the following C code: <br>&nbsp; &nbsp; &nbsp; #include &lt;stdio.h&gt;<br><br>&nbsp; &nbsp; &nbsp; void main(void)<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int i;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d", &amp;i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("/nSTDIn is %d!/n", i);<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp;<br><br>Create a batch file, named REDIRECT.BAT, that contains only the following command line: <br><br>type stdin.txt | consol.exe &gt; stdout.txt<br><br>Create a new text file using Notepad or any text editor. Enter an integer and press the ENTER key. Save the file as "stdin.txt." <br><br><br>Start a new project in Visual Basic. Form1 is created by default. <br><br><br>Add the following code to the General Declarations section of Form1: <br>&nbsp; &nbsp; &nbsp; Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal _<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwAccess As Long, ByVal fInherit As Integer, ByVal hObject _<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;As Long) As Long<br><br>&nbsp; &nbsp; &nbsp; Private Declare Function CloseHandle Lib "kernel32" (ByVal _<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hObject As Long) As Long<br><br>&nbsp; &nbsp; &nbsp; Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _<br>&nbsp; &nbsp; &nbsp; &nbsp;hHandle As Long, ByVal dwMilliseconds As Long) As Long<br><br>&nbsp; &nbsp; &nbsp; Const SYNCHRONIZE = &amp;H100000<br>&nbsp; &nbsp; &nbsp; Const NORMAL_PRIORITY_CLASS = &amp;H20&amp;<br>&nbsp; &nbsp; &nbsp; Const INFINITE = -1&amp;<br>&nbsp;<br><br><br><br>Add the following code to the Form1_Click event: <br><br>&nbsp; &nbsp; &nbsp; ProcessID&amp; = Shell("test.bat", vbNormalFocus)<br>&nbsp; &nbsp; &nbsp; ProcessHandle&amp; = OpenProcess(SYNCHRONIZE, True, ProcessID&amp;)<br>&nbsp; &nbsp; &nbsp; WaitForSingleObject ProcessHandle&amp;, -1&amp;<br>&nbsp; &nbsp; &nbsp; CloseHandle ProcessHandle&amp;<br><br>Save Form1 and Project1 to the same directory as REDIRECT.BAT and CONSOL.EXE. Press the F5 key to run the program. Click Form1. A console window is displayed briefly and closes itself. The STDOUT.TXT file is then created in the same directory. <br><br>触类旁通吧!
 
我有个办法,其实我也做了一部分的F77Shell For Win<br>就是你编辑一个BAT文件,在BAT文件里面建立输出到固定文件<br>然后在Delphi中读出这个文件就可以了<br>bat文件的内容如下<br><br>ECHO **** FORTRAN 77 Compiling ****&gt;Temp1.TXT<br>FOR1 %1;&gt;&gt;Temp1.Txt<br>IF ERRORLEVEL 1 GOTO ERROUT<br>PAS2&gt;&gt;Temp1.Txt<br>IF ERRORLEVEL 1 GOTO ERROUT<br>rem LINK %1,%1,NUL;&gt;&gt;Temp1.TXT<br>GOTO OUT<br>:ERROUT<br>ECHO Error in file, Complier Stopped !&gt;&gt;Temp1.TXT<br>ECHO Error&gt;&gt;Temp1.TXT<br>:OUT<br>ECHO Success Complier !&gt;&gt;Temp1.TXT<br>ECHO Success&gt;&gt;Temp1.TXT<br>ECHO ON<br><br>读出Temp1.txt文件就可以了解,出错在哪里了<br>不过是个笨办法,见笑见笑
 
多人接受答案了。
 
后退
顶部