INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a Computer / IT professional? Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Feedback
"...with companys cutting back on training, lack of true support by makers of software, the forums are a great tool in your cyber-toolbox...."
Geography
Where in the world do Tek-Tips members come from?
|
Microsoft: Visual FoxPro FAQ
|
Tips -N- Tricks
|
How to run DOS program in background effectively
Posted: 1 Nov 03 (Edited 1 Nov 03)
|
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
*** --------------- ** Example 1, using Run/! command 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
** Example 2, using ShellExecute If file('test.txt') Erase test.txt endif Declare Integer ShellExecute in Shell32.dll ; Long nhWnd, String cAction, String cFile, ; String cParam, String cDirectory, Integer nShow lcCmd = GetCommander(.T.) lcParam = '/C ping localhost > test.txt' Clear ? 'Using ShellExecute. Pinging localhost, wait...' ShellExecute(0, Null, lcCmd, lcParam, Null, 0) = inkey(8) If file('test.txt') lcString = FileToStr('test.txt') ? lcString = inkey(0) else ?? ' Failed!' endif
** Example 3, using Windows Script ** Provided by: Ramani ** WSH must exist on client computer 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
** The function Function GetCommander(tlFilename) Local lcDir, lcCmd ** Use COMSPEC instead of WINDIR. Corrected by: Ramani 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
Return lcCmd EndFunc
*** ---------------
|
Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum |
|
 |
|
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close