Jon P
Jon P

Reputation: 821

Process.Start() arguments does not take effect

I have a code here in C#, the function of this is to generate a list of files in a folder:

ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe", "dir /B /S *.* > D:\\tempf.txt");
processStartInfo.WorkingDirectory = @"C:\test";
Process.Start(processStartInfo);

This will just run cmd on C:\test and the arguments are not executed. Is there something missing?

Upvotes: 1

Views: 158

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503529

You need the /c argument to say "execute the rest as a command":

ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe",
    "/c dir /B /S *.* > D:\\tempf.txt");

From the help for CMD:

/C      Carries out the command specified by string and then terminates

Upvotes: 4

Related Questions