我试图通过C#执行OS命令。我从this webpage采取了以下代码:在文件C上执行OS命令#
//Execute command on file
ProcessStartInfo procStart =
new ProcessStartInfo(@"C:\Users\Me\Desktop\Test\System_Instructions.txt",
"mkdir testDir");
//Redirects output
procStart.RedirectStandardOutput = true;
procStart.UseShellExecute = false;
//No black window
procStart.CreateNoWindow = true;
//Creates a process
System.Diagnostics.Process proc = new System.Diagnostics.Process();
//Set start info
proc.StartInfo = procStart;
//Start
proc.Start();
但是当我尝试运行代码我得到以下错误:
{"The specified executable is not a valid application for this OS platform."}
我在做什么错?我试过this example as well,但得到了同样的问题。
您尝试执行文本文件,该文件(错误指示)不可执行。如果你想创建一个文件夹,我建议使用System.IO类,例如DirectoryInfo,Fileinfo等。 –
从描述中完全不清楚你试图完成什么。 – MarkPflug