传递路径,旨在通过CMD没有的ProcessStartInfo工作 [英] Passing paths to cmd using ProcessStartInfo not working as intended
问题描述
进出口使用过程和的ProcessStartInfo推出与通常的重定向输出等。但是我我特林推出带有参数的命令行执行一个cmd窗口,即使字符串是正确的,当我把它回显到CMD时,我运行它没有回声,我得到'C:\Program'是不是一个公认的INTERAL或外部命令,如果路径不是在引号和空间把它扔了。
$ b。$ b
任何帮助greatley感激!
静态无效的备份(字符串机器名)
{
进程p =新工艺();
p.StartInfo =新的ProcessStartInfo(CMD,/ C \C:\\Program Files\\Citrix\\XenCenter\\xe.exe\VM -export VM =+计算机名+-s 192.168.00.00 -u根-pw密码1名= \!C:\\VMs\\+计算机名+.xva\)
{
RedirectStandardOutput = TRUE,
UseShellExecute =假,
CreateNoWindow = FALSE
};
p.Start();
字符串输出= p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(输出);
}
您不应该使用 CMD来称呼这一点 - 它实际上在这种情况下,工作对你,没有任何用处。只需直接调用可执行文件:
p.StartInfo =新的ProcessStartInfo(
@C:\Program Files\\ !\\Citrix\XenCenter\xe.exe,
VM-VM出口=+计算机名+-s 192.168.00.00 -u根-pw密码1名= \C:\\ VMs\\+计算机名+.xva\)
{
RedirectStandardOutput = TRUE,
UseShellExecute =假,
CreateNoWindow = FALSE
} ;
Im using Process and ProcessStartInfo to launch a cmd window with the usual redirected output etc. However i'm tring to launch a command line executable with arguments, and even though the string is correct when i echo it to the cmd, when i run it without echo i get "'C:\Program' is not a recognized as an interal or external command" as if the path isn't in quotation marks and the space is throwing it off.
Any help greatley appreciated!
static void Backup(string machinename)
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("cmd", "/c \"C:\\Program Files\\Citrix\\XenCenter\\xe.exe\" vm-export vm=" + machinename + " -s 192.168.00.00 -u root -pw Password1! filename=\"C:\\VMs\\" + machinename + ".xva\"")
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = false
};
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(output);
}
You shouldn't use "cmd" to call this - it's actually working against you in this case, and serves no purpose. Just call your executable directly:
p.StartInfo = new ProcessStartInfo(
@"C:\Program Files\Citrix\XenCenter\xe.exe",
"vm-export vm=" + machinename + " -s 192.168.00.00 -u root -pw Password1! filename=\"C:\\VMs\\" + machinename + ".xva\"")
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = false
};
这篇关于传递路径,旨在通过CMD没有的ProcessStartInfo工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!