5
System.Diagnostics.Process proc0 = new System.Diagnostics.Process();
proc0.StartInfo.FileName = "cmd";
proc0.StartInfo.WorkingDirectory = Path.Combine(curpath, "snd");
proc0.StartInfo.Arguments = omgwut;

And now for some background...

string curpath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

omgwut is something like this:

copy /b a.wav + b.wav + ... + y.wav + z.wav output.wav

And nothing happens at all. So obviously something's wrong. I also tried "copy" as the executable, but that doesn't work.

4 Answers 4

16

Try the prefixing your arguments to cmd with /C, effectively saying cmd /C copy /b t.wav ...

According to cmd.exe /? using

/C <command>

Carries out the command specified by string and then terminates

For your code, it might look something like

// .. 
proc0.StartInfo.Arguments = "/C " + omgwut;

Notes:

  • A good way to test whether your command is going to work is to actually try it from a command prompt. If you try to do cmd.exe copy ... you'll see that the copy doesn't occur.
  • There are limits to the length of the arguments you can pass as arguments. From MSDN: "The maximum string length is 2,003 characters in .NET Framework applications and 488 characters in .NET Compact Framework applications."
  • You can bypass the shelling out to command by using the System.IO classes to open the files and manually concatenate them.
Sign up to request clarification or add additional context in comments.

Comments

7

Try this it might help you.. Its working with my code.

System.Diagnostics.ProcessStartInfo procStartInfo =
    new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);
  }
  catch (Exception objException)
  {
  // Log the exception
  }

1 Comment

You should add a throw; after logging the exception, unless this code is at the top level of the program. That will allow the exception to propagate to the callers.
1

Daniels cmd /c idea will work. Keep in mind there is a limit to the length of a command line probably 8k in your case see this for details.

Since you are in a .Net app anyway, File.Copy may be quite a bit easier/cleaner than this approach.

1 Comment

He's trying to append multiple files; not sure if you can do that with File.Copy
1

Even you can try this.. this is even better.

System.Diagnostics.Process proc = new System.Diagnostics.Process(); 

proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="iexplore";
proc.StartInfo.Arguments="http://www.microsoft.com";

proc.Start();

proc.WaitForExit();

MessageBox.Show("You have just visited " + proc.StartInfo.Arguments);

Comments

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.