0

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();
        }
    }
5
  • NOTE: i just added the test.txt instead of LPT1 for testing purpose. Commented Aug 17, 2012 at 18:47
  • That's correct, you just need the "/c" as the first parameter. Commented Aug 17, 2012 at 18:56
  • Do you actually have FileInfo instances being retrieved from listbox1.Items? Commented Aug 17, 2012 at 18:58
  • yeap. so far it works :) without path.GetdirectoryName it would'nt work sayin something like" path is invalid" Commented Aug 17, 2012 at 19:00
  • but that also opens up for my next question. how do I add in my file names into to cmd line ?? Commented Aug 17, 2012 at 19:01

2 Answers 2

1
string strCmdText;
strCmdText= "/C copy /b myfile.txt test.txt";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

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

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

1 Comment

thanks. it sure did something now. the CMD windows pops up quick and closes again saying that LPT1 is not recognize device. but thats probably cause I dont have LPT port in my laptop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.