When we use RUN command with /N7, sometimes the program doesn't execute properly or not run at all. My suspect is, VFP execute the command and get back to VFP too fast, so it doesn't have enough time to create DOS environment.
In order to run DOS program running in background properly we can simply call DOS Commander (Command.com for Win9X/ME, Cmd.exe for NT/2K/XP) and let it do the job for our application, while we can continue our program.
Thanks to:
1. Jim Osieczonek (jimoo)
For encouraging me to make FAQ. So this is my first time
2. Ramani - (Subramanian.G)
For the correction and provided another example
*** ---------------[color blue]
[color green]** Example 1, using Run/! command[/color]
If file('test.txt')
Erase test.txt
endif
lcCmd = GetCommander() + ' ping localhost > test.txt'
Clear
? 'Using RUN command. Pinging localhost, wait...'
RUN /N7 &lcCmd
= inkey(8)
If file('test.txt')
lcString = FileToStr('test.txt')
? lcString
= inkey(0)
else
?? ' Failed!'
endif
[color green]** Example 3, using Windows Script
** Provided by: Ramani
** WSH must exist on client computer[/color]
If file('test.txt')
Erase test.txt
endif
loShell = CreateObject("wscript.shell")
lcCmd = GetCommander()
lcCmd = lcCmd + ' ping localhost > test.txt'
Clear
? 'Using Windows Script. Pinging localhost, wait...'
loShell.Run(lcCmd, 0, .f.)
= inkey(8)
If file('test.txt')
lcString = FileToStr('test.txt')
? lcString
= inkey(0)
else
?? ' Failed!'
endif
[color green]** The function[/color]
Function GetCommander(tlFilename)
Local lcDir, lcCmd
[color green]** Use COMSPEC instead of WINDIR. Corrected by: Ramani[/color]
lcDir = AddBS(JustPath(GetEnv('ComSpec')))
If tlFilename && get the filename only
If file(lcDir + 'Cmd.exe') && Is NT ?
lcCmd = 'Cmd.exe'
else
lcCmd = 'Command.com'
endif
else
If file(lcDir + 'Cmd.exe')
lcCmd = lcDir + 'Cmd.exe /C'
else
lcCmd = lcDir + 'Command.com /C'
endif
endif
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.