从 VS Addin 调用时 process.start() 挂起
我正在使用 Visual Studio 2005 的一个插件来调用外部进程。
当我在插件之外运行代码时 - 即在独立项目中,它工作正常。 但是,当我将其作为插件的一部分调用时,会进行 Process.Start() 调用,但随后什么也没有发生,后续的代码行永远不会到达。
我尝试过以标准权限和提升权限运行 VS,但得到了相同的效果。
代码如下 - 单击自定义菜单项时调用它:
string documentPath = @"C:\TestCode\TestApp\Testform.cs";
string folder = Path.GetDirectoryName(@"C:\TestCode\TestApp\");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "notepad.exe";
p.StartInfo.Arguments = documentPath;
p.StartInfo.UseShellExecute = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
我尝试了不同的可执行文件,但这没有任何区别。 我在VS中处理这个问题的方式是错误的吗? 任何帮助表示赞赏。
I'm playing about with an addin to Visual Studio 2005 that calls an external process.
When I run the code outside of the addin - i.e. in a standalone project it works fine. However when I call it as part of a addin the Process.Start() call is made but then nothing happens, the subsequent lines of code are never reached.
I have tried running VS with standard and elevated priviliges but get the same effect.
The code is below - it is called when clicking on a custom menu item:
string documentPath = @"C:\TestCode\TestApp\Testform.cs";
string folder = Path.GetDirectoryName(@"C:\TestCode\TestApp\");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "notepad.exe";
p.StartInfo.Arguments = documentPath;
p.StartInfo.UseShellExecute = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
I've tried different executables, but this does not make any difference. Am I going about this the wrong way in VS? Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过尝试/捕获吗? 特别是有许多与 VS 扩展的工作路径/当前目录相关的问题(但我希望记事本至少可以工作)。
我也不确定您希望该代码做什么(就重定向 notepad.exe 的标准输出而言); 你能澄清一下吗?
目前不是问题,但请注意,当使用路径作为参数时,您需要从头开始添加引号 - 即
(如果路径中有空格)
Have you tried try/catch? In particular there are a number of gotchas relating to the working path / current directory with VS extensions (but I would expect notepad to work, at least).
I'm also not sure what you expect that code to do (in terms of redirecting stdout of notepad.exe); can you clarify?
Not an issue at the moment, but note that when working with paths as arguments, you'll want to add quotes from the start - i.e.
(in case the path has spaces in it)