简体   繁体   English

带有更改目录的命令行参数

[英]Command Line arguments with change directory

I am trying to run command line arguments from C# console app. 我正在尝试从C#控制台应用程序运行命令行参数。

Code is: 代码是:

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();

I don't see any results in cmd window. 我在cmd窗口中看不到任何结果。 The actual arguments in cmd window is: cmd窗口中的实际参数为:

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

Please help 请帮忙

Add /c to your arguments. /c添加到您的参数。 This will make cmd.exe reconise that you are passing a command. 这将使cmd.exe符合您正在传递命令的要求。

Also at the start of string[] MyArguments = { @"/C:\\\\Program Files (x86)\\\\salesforce.com\\\\Data Loader\\\\bin", "process.bat", "\\"PathName"", "BeanName"}; 同样在string[] MyArguments = { @"/C:\\\\Program Files (x86)\\\\salesforce.com\\\\Data Loader\\\\bin", "process.bat", "\\"PathName"", "BeanName"}; there is a / before C: which will cause an error in cmd. C:之前有一个/ ,这将导致cmd中的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM