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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.