我需要运行批处理文件,其中路径(可以包含空格)作为参数。
批处理文件非常简单:
回波消失 回波%1 > echotest.txt
用于运行这个批处理文件的Csharp代码:
ProcessStartInfo info = new ProcessStartInfo();
info.UserName = KIM_USER;
info.Password = ConvertToSecureString(KIM_USER_PASSWORD);
info.FileName = theTask.Path;
info.Arguments = "\"" + TranslateParameter(theTask.Parameter) + "\"";
info.Domain = Environment.MachineName;
info.WorkingDirectory = Path.GetDirectoryName(theTask.Path);
info.UseShellExecute = false;
info.CreateNoWindow = true;
Process batProcess = Process.Start(info);
batProcess.WaitForExit();
基本上,在参数中,例如{Test_Path},这是在TranslateParameter转换成实际路径中,例如: D:\Test path \(包含空格)
这对我不起作用,它每次都会返回退出代码1。
如果我从info.Arguments中删除\“,它可以工作,但是在输出文件中只有D:\Test
有什么建议吗?
问候
发布于 2015-02-06 08:18:33
如果这样可行的话,你能试试这个吗?
ProcessStartInfo info = new ProcessStartInfo();
info.UserName = KIM_USER;
info.Password = ConvertToSecureString(KIM_USER_PASSWORD);
info.FileName = theTask.Path + " \"" + TranslateParameter(theTask.Parameter) + "\"";
//info.Arguments = "\"" + TranslateParameter(theTask.Parameter) + "\"";
info.Domain = Environment.MachineName;
info.WorkingDirectory = Path.GetDirectoryName(theTask.Path);
info.UseShellExecute = false;
info.CreateNoWindow = true;
Process batProcess = Process.Start(info);
batProcess.WaitForExit();
https://stackoverflow.com/questions/28364640
复制