如何使用C#在命令提示符下更改目录位置? [英] how to change the directory location in command prompt using C#?
本文介绍了如何使用C#在命令提示符下更改目录位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过以下代码使用C#成功打开了命令提示符窗口。
I have successfully opened command prompt window using C# through the following code.
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = @"d:\pdf2xml";
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.WriteLine(@"pdftoxml.win32.1.2.7 -annotation "+filename);
p.StandardInput.WriteLine(@"cd D:\python-source\ds-xmlStudio-1.0-py27");
p.StandardInput.WriteLine(@"main.py -i example-8.xml -o outp.xml");
p.WaitForExit();
但是,我还通过了更改目录的命令。
But, i have also passed command to change the directory.
问题:
- 如何更改目录位置?
- Cmd提示打开后将始终显示...
请指导我摆脱那些问题...
Please guide me to get out of those issue...
推荐答案
您可以使用p.StandardInput.WriteLine将命令发送到cmd窗口。为此,只需将p.StartInfo.RedirectStandardOutput设置为ture。如下所示
You can use p.StandardInput.WriteLine to send commands to cmd window. For this just set the p.StartInfo.RedirectStandardOutput to ture. like below
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
//p.StartInfo.Arguments = @"/c D:\\pdf2xml";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.WriteLine(@"cd D:\pdf2xml");
p.StandardInput.WriteLine("d:");
这篇关于如何使用C#在命令提示符下更改目录位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文