tags:

views:

115

answers:

3

I am trying to execute DOS commands in ASP.NET 2.0. What I have now calls a BAT file which, in turn, calls a CMD file. It works (with the end result being a file gets ftp'ed). However, I'd like to dump the BAT and CMD files and run everything in .NET. What is the format of sending multiple arguments into the command window? Here is what I have now.

The .NET Code:

    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.EnableRaisingEvents = false;
    proc.StartInfo.FileName = "C:\\MyBat.BAT";
    proc.Start();
    proc.WaitForExit();

The Bat File looks like this (all it does is run the cmd file):

ftp.exe -s:C:\MyCMD.cmd

And here is the content of the Cmd file:

open <my host>
<my user name>
<my pw>
quote site cyl pri=1 sec=1 lrecl=1786 blksize=0 recfm=fb retpd=30
put C:\MyDTLFile.dtl 'MyDTLFile.dtl'
quit
+2  A: 

You use ProcessStartInfo.Arguments to hand over your arguments:

proc.StartInfo.FileName = @"ftp.exe";
proc.StartInfo.Arguments = @"-s:C:\MyCMD.cmd";

But - that's not what you want, since you want to replace the cmd file, too. However, the content is not a commandline argument which is handed over to ftp.exe. It is rather an input script. So it will not work to pass the content as an argument.

To make even the cmd file disappear you have to use the standard input and output. See for instance Process.StandardInput.

tanascius
A: 

Use Process.StartInfo.Arguments.

JSBangs
A: 

If you're starting a new process, just set the ProcessStartInfo.Arguments property to a string containing all your arguments, just as if you had typed them on the command line.

As an aside, since it looks like you're trying to script the command-line FTP client, you might be interested in the C# FTP Client library on CodeProject, or perhaps one of the answers to this other StackOverflow question.

Daniel Pryden
Set the string. I got you there. But how are they separated? Is it a string of comma separated commands?
donde
@donde: You can set only one argument line. The separation of different arguments is given by the program you call. For instance `ftp.exe -v -n -i -s:mycmd.cmd -A` (here they are separated by a space and start with a dash). But **passing more than one line is not possible**.
tanascius