Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output redirection with Wscript.shell 1

Status
Not open for further replies.

foxbldr

Programmer
Apr 16, 2002
109
CA
Hi Friends,

Within VFP6, I am using Wscript.shell object's run method to run an external program. External program's output is redirected to a text file called output.txt.

Code:
lcExecStr="abc.exe >output.txt"
loShell=createobject('Wscript.shell')
loShell.run(lcExecStr,0,.t.)
...

My problem is that output.txt is not getting created. Is this a VFP problem?

Thanks

Foxbldr
 
Foxbldr,

It looks to me like you should be able to run the command
Code:
abc.exe >output.txt
from a DOS window or from the Run item on the start menu.

Have you tried that and does it then create the txt file?

Stewart
 
Foxbldr

I've had similar problems before with command line utilities not outputting to a file, and resolved it by putting 'abc.exe >output.txt' into a .bat file and then running the .bat file.

May be worth a try...

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.com
PDFcommandertm.co.uk


 
The redirection operators: <, >, and |, don't work the same in all OSs or in CMD vs. Command (in NT / 2000 / XP / 2003).

Under what OS are you running?

Rick
 
Rick,

I am using both WIN98 and WIN XP.
Thanks

Foxbldr
 
The redirection operators: <, >, and |, don't work the same in all OSs or in CMD vs. Command (in NT / 2000 / XP / 2003).

Like Rick is alluding to here, the important thing here is that they only work in a DOS environment. Whether it be command.com (actual DOS) or cmd.exe (emulated DOS), WSH is going to run it in the windows environment to a windows device context. You won't be able to redirect the output which would normally go to the screen, into a file.
As far as I know, the only way to get your desired results would be to run it as a batch file.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Dave S,

Yes, you are correct. It doesn't work with Windows environment. But, batch file does the trick.


Foxbldr
 
Hi foxbldr,

The problem with most of these shell commands is the lack of reference to ComSpec

** Note the spaces within the square bracket and done remove them.

lcCmd = GETENV("ComSpec") + [ /C ]
lcCmd = lcCmd + [abc.exe >output.txt]
loShell=createobject('Wscript.shell')
loShell.run(lcCmd,0,.t.)

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Hi Ramani,

Thanks for the explanation. Though I used Chris's method, I bumped into another situation. When I run the batch file, the dos window stays(even after running abc.exe and creating output.txt) and does not return to my VFP program.


eg:

strCommand='abc.exe >output.txt'
=strtofile(strCommand,'abc.bat')
loshell=createobject("Wscript.shell")
loshell.run('abc.bat',0, .t.)

How can I solve this problem?


Foxbldr


 
Hi Foxbldr,

lcCmd = GETENV("ComSpec") + [ /C ]
lcCmd = lcCmd + [abc.exe >output.txt]
loShell=createobject('Wscript.shell')
loShell.run(lcCmd,0,.t.) && Zero suppresses the DOS Black window - 1 in the place of 0 will show the window.

:)



____________________________________________
ramani - (Subramanian.G) :)
 
i am going down similar path. i don't have final answer for you yet, but something to look at.

instead of
shl.run(~~~)
look at
shl.exec(~~~)

per msdn, ... along with access to the StdIn, StdOut, and StdErr channels.

i'm digging into this to use an hta file to script an ftp upload.

hth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top