Run bat file with parameters from MVC controller

I'm trying to run a bat file (with parameters) from an MVC controller.  Can somebody please tell me what I'm doing wrong?  When I run this without parameters it works.  When I add parameters, it doesn't.  I get no errors.

This is what it should look like at the command line:
c:
cd C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow
vstest.console.exe "c:\Program Files (x86)\myFolder\SeleniumTest.dll" /TestCaseFilter:"TestCategory=Main Menus"

Open in new window


code snippet from Controller:
steName = Name; //parameter

            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.StartInfo.WorkingDirectory = @"C:\scripts";
                myProcess.StartInfo.FileName = @"C:\scripts\CmdRunTests.bat";
myProcess.StartInfo.Arguments = steName;
//myProcess.StartInfo.Arguments = String.Format("\"{0}\"", steName); //Also tried this line
                myProcess.Start();

bat file:
set steName=%1
@echo off
c:
cd C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow
vstest.console.exe "c:\Program Files (x86)\myFolder\SeleniumTest.dll" /TestCaseFilter:"TestCategory=%1"
pause

Open in new window

sg1 capricaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MishaProgrammerCommented:
1) If you use tag "code", it is more simple to read your question.
2) There is a good article about parameters and batfiles
https://ss64.com/nt/syntax-esc.html
3) Try to use this code:
var proc = new ProcessStartInfo("cmd.exe")
{
    Arguments = string.Format("/с \"\"batchfile.bat\" \"{0}\" \"{1}\" \"{2}\"\"", arg1, arg2, arg3),
    CreateNoWindow = true,
    UseShellExecute = false,
    RedirectStandardError = true,
    RedirectStandardOutput = true
};

using (var process = Process.Start(proc))
{
    process.WaitForExit();
}

Open in new window

0
sg1 capricaAuthor Commented:
I'm new at this.  Could you make it specific to my code and my bat file?
0
MishaProgrammerCommented:
Try this code:
			string steName = "Name";
			var proc = new ProcessStartInfo("cmd.exe")
			{
				Arguments = string.Format("/c \"\"CmdRunTests.bat\" \"{0}\"", steName),
				WorkingDirectory = @"C:\scripts",
				CreateNoWindow = true,
				UseShellExecute = false,
				RedirectStandardError = true,
				RedirectStandardOutput = true
			};
			using (var process = Process.Start(proc))
			{
				process.WaitForExit();
			}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sg1 capricaAuthor Commented:
I tried this with the parameter in my bat file set to %1 and then tried it after changing it to %0 and it still didn't work or give me any errors.  Can you look at the parameters in the bat file and tell me whether I'm doing that part right?  It works without parameters and arguments.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.