【发布时间】:2011-08-09 21:06:14
【问题描述】:
我正在尝试通过 C# 执行操作系统命令。我有以下代码取自this webpage:
//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 等。
-
从您的描述中完全不清楚您要完成什么。