Post by David Martin on Oct 13, 2019 22:53:07 GMT 1
Is there a way to run an external EXE from a FoxProX program and pass it command line arguments?
For example: When running under 32 bit windows we can do something like RUN MYUTIL.EXE > OUTPUT.TXT that would run the MYUTIL.EXE and send all output to the OUTPUT.TXT file. We then read the contents of that file into the FoxPro program.
This doesn't work when running on Windows 10 64 bit and using VDOS 5/1/2019 ... what happens is the MYUTIL.EXE is run but the command line arguments are ignored and the OUTPUT.TXT file is not created...or is created empty.
We also need to be able to run other utilities that are EXE files that get filenames as command line arguments ... so: OTHERUTIL.EXE INPUT.TXT
These external EXEs are 32 bit Windows programs and do work as expected when run from the command prompt in 64 bit.
FoxPro calls upon the command shell to execute external ‘stuff’. With NTVDM this was CMD, a Windows program using the window of NTVDM. In vDos this is however the DOS-like internal command shell. If that encounters the trailing “> OUTPUT.TXT” it will redirect its standard output and eventual to start DOS program to OUTPUT.TXT. MYUTIL.EXE is however a Windows program that can’t run in the vDos window, and its standard output isn’t redirected. You need to use CMD (like NTVDM did), and make sure the redirection isn’t ‘eaten’ by the vDos command shell. For that you have to enclose the command line in some quotes:
RUN CMD '"/c MYUTIL.EXE > OUTPUT.TXT"
The current vDos version is in the habit to remove pairs of quotes, so the extra single leading one. CMD also needs a separate window, so you might want to hide that popping up:
RUN CMD HIDE'"/c MYUTIL.EXE > OUTPUT.TXT"
And keep in mind, Windows programs deal with the Windows file system, they are unaware of that of vDos.
No such thing as a ‘reread disk’ since vDos doesn’t cache, the file just isn’t made yet. CMD returns immediately w/o waiting for MYUTIL.EXE to finish, its return code will also only reflect whether MYUTIL.EXE could be started. Even adding WAIT (so WAITHIDE) doesn’t prevent CMD to return immediately after it starts an external command or program. But MYUTIL.EXE is also a CLI program, you could try. Else your program just has to wait for the file being created.
Post by David Martin on Oct 14, 2019 14:13:59 GMT 1
Yes, I realize FoxPro doesn't wait for CMD to finish but returns immediately.
There is a loop in the code that waits for up to 10 seconds or when it sees the file and then continues ... when running under vDOS it goes right through this loop ... when in Windows 32 bit it usually takes a couple of loops before it goes by.
So either the file is created, which I can see it on disk in Windows Explorer, or the FoxPro WAIT command is not being honored and the loop is just blasting through 10 times before the file is created.
pLoop = 1 DO WHILE pLoop < 10 AND NOT FILE("OUTFILE.TXT") pLoop = pLoop + 1 WAIT "" NOWAIT TIMEOUT 1 && Pause for 1 second ENDDO