简体   繁体   中英

process.start() hangs when called from VS Addin

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 - ie 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.

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 - ie

p.StartInfo.Arguments = "\"" + documentPath + "\"";

(in case the path has spaces in it)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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