C#Console在调用cmd的时候无论是cd还是F:盘符都无法更改cmd命令执行目录,有什么办法能解决呢?
一般问题倒好应付,但是遇到调用“使用log4j写log的程序”就会导致log位置错乱。请问大佬怎么解决???
这是代码
public static string input(string Input)
{
string logs = "";
ProcessStartInfo start = new ProcessStartInfo
{
FileName = "cmd.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = false,
RedirectStandardInput = true
};
Process Reader = Process.Start(start);
using (Reader)
{
Reader.OutputDataReceived += new DataReceivedEventHandler(OutputDataReceived);
Reader.BeginOutputReadLine();
Reader.StandardInput.WriteLine(Input);//输入命令
Reader.WaitForExit();
}
void OutputDataReceived(object sender, DataReceivedEventArgs Outputs)
{
if (null != Outputs)
{
Console.WriteLine(Outputs.Data);
logs = logs +"\n"+ Outputs.Data;
}
}
return logs;