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!

How to execute a .bat program ???

Status
Not open for further replies.

Seb104

IS-IT--Management
Aug 22, 2002
3
FR
I'm new to this programing world, so please use an understandable language :)

I need to execute remotely (from any browser) some .bat files located on an IIS web server. Let say for example c:\test.bat. I try to use asp and VBscripts for that.

What script can be used to execute this program?
 
You can get more detailed explanations and examples in the ASP forum.

But in theory, just set up an ASP page including

Set oShell = CreateObject("WScript.Shell")
nReturn = oShell.Run("C:\test.bat",0,True)

or

nReturn = oShell.Run("%COMSPEC% /C C:\test.bat",0,True)

Obviously there are going to be permissions you'll need to consider. Jon Hawkins
 
In this case, nReturn is the returned error code.

What if you wanted to get back the StdOut of test.bat?

I have a test.bat which generates some output on the command line, and I need to get at this output.
 
That depends on what's hosting your script.

Within ASP, you've got at least two options, depending on test.bat. You can either 1) attempt to send the output to a text file and then read in that text file.

nReturn = oShell.Run("%COMSPEC% /C C:\test.bat >C:\test.txt",0,True)

or 2) setup a .VBS script that you execute with WSH, which does provide access to the StdIn, StdOut, & StdErr streams. Your .VBS would then write the StdOut stream to a text file which would be picked up by your ASP. Search this form for StdIn or StdOut - there are some examples.
Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top