更改目录

时间:2016-07-20 09:31:56

标签: c# command-line-arguments filepath

我正在尝试从C#console app运行命令行参数。

代码是:

string[] MyArguments = { "/c", @"'C:\Program Files (x86)\salesforce.com\Data Loader\bin\process.bat'",  "\"C:\\Program Files (x86)\\salesforce.com\\Data Loader\\samples\\conf\"", "accountMasterProcess" };

ProcessStartInfo startInfo = new ProcessStartInfo();
            Process process;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = String.Join(" ", MyArguments);


            process = Process.Start(startInfo);
            startInfo.RedirectStandardError = true;
            startInfo.RedirectStandardOutput = true;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.OutputDataReceived += (sender, arg) => Console.WriteLine("received output: {0}", arg.Data);
            process.Start();
            //process.BeginOutputReadLine();
            process.WaitForExit();
            string output = process.StandardOutput.ReadToEnd();
            string error = process.StandardError.ReadToEnd();

            exitCode = process.ExitCode;

            Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
            Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
            Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
            process.Close();

我在cmd窗口中看不到任何结果。 cmd窗口中的实际参数是:

C:\Program Files (x86)\salesforce.com\Data Loader\bin>process.bat "C:\Program Files (x86)\salesforce.com\Data Loader\samples\conf" accountMasterProcess

请帮忙

1 个答案:

答案 0 :(得分:0)

/c添加到您的参数中。这将使cmd.exe重新确认您正在传递命令。

同样在string[] MyArguments = { @"/C:\\Program Files (x86)\\salesforce.com\\Data Loader\\bin", "process.bat", "\"PathName"", "BeanName"};开始时/之前C:会导致cmd出错。