Mikkel Eriksen
Mikkel Eriksen

Reputation: 69

adding arguments to process not working?

I got this program written in C# WinForms.

im using system.diagnostic to create a CMD process. with that cmd i want some arguments but they are not present or working :S dont know why ?!

NOTE: im not sure how to use more than 1 argument, correct me if im wrong :D im trying to replicate the "copy /b %filename% lpt1" command....

here is my code:

    public void OutputBtn_Process_Click(object sender, EventArgs e)
    {
        foreach (FileInfo fi in listBox1.Items)
        {
            Process process1 = new Process();
            process1.StartInfo.UseShellExecute = false;
            process1.StartInfo.Arguments = "copy /b myfile.txt test.txt";
            //process1.StartInfo.LoadUserProfile = true;
            process1.StartInfo.FileName = "cmd.exe";
            process1.StartInfo.WorkingDirectory = Path.GetDirectoryName(fi.FullName);
            process1.Start();
        }
    }

Upvotes: 0

Views: 2762

Answers (2)

rene
rene

Reputation: 42494

Try this

 process1.StartInfo.Arguments = "/C \"copy /b myfile.txt LPT1:\""; 

The documentation on Windows 7 command-line tool cmd.exe

Upvotes: 0

Hassan Boutougha
Hassan Boutougha

Reputation: 3919

string strCmdText;
strCmdText= "/C copy /b myfile.txt test.txt";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);

Upvotes: 1

Related Questions