Sending arguments to Developer Command Prompt for

2019-08-21 16:49发布

I am not able to pass some parameters to my Dev cmd prompt for vs, I can do it with the classic cmd but not with this one. And I need it because I want to execute CodedUITests from an executable.

This is what my code looks like:

String Path = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Visual Studio 2012\Visual Studio Tools\Developer Command Prompt for VS2012.lnk";

ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = Path;
proc.UseShellExecute = true;
proc.Arguments =  @"/c MSTest/h";
Process.Start(proc);

It starts, but no args are inserted,what am I doing wrong ?

EDIT 1 - None of these are working

Process.Start(Path, @"/c "+"MSTest/h"); - err : invalid path - in dev cmd prompt

OR

Process.Start(Path, @"/c ""MSTest/h"); -  err: invalid path - in dev cmd prompt

OR

Process.Start(Path, @"/c MSTest/h"); - nothing

OR

Process.Start(Path, "/c MSTest/h"); -nothing

OR

Process.Start(Path,  "MSTest/h");  -nothing

EDIT 2 - This is how my final code looks like, partially working, dev cmd starting, but no way to parse args into it because any args I pass they go straight to cmd not to dev-cmd

// ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", @"%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat""");
            ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", @"%comspec% /k ""C:\Users\butoiu.edward\Desktop\VsDevCmd1.bat");            
            procStartInfo.UseShellExecute = false;
           // procStartInfo.Arguments = "/k MSTest";
            Process proc = new Process();

            proc.StartInfo = procStartInfo;
            proc.Start();


            proc.WaitForExit();

2条回答
成全新的幸福
2楼-- · 2019-08-21 17:21

lnk" file it is actually a link of visual studio cmd prompt. Instead of this location you try original file located at "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"

String Path = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat";

ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = Path;
proc.UseShellExecute = true;
proc.Arguments =  @"/c MSTest/h";
Process.Start(proc);

I hope this will help you.

查看更多
smile是对你的礼貌
3楼-- · 2019-08-21 17:26

Did you try this way?

    void OpenWithArguments()
    {
        Process.Start("IExplore.exe", "www.northwindtraders.com");
        Process.Start("path to exe", "argument");
    }

-- FMI MSDN LINK

Update:

I assume it will work this way... but not sure

Open sys default cmd prompt.. and give first param as batch file path (C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat) and give a space and add next attribute.

Process.Start("Path to EXE", "arg1 arg2")
查看更多
登录 后发表回答