views:

101

answers:

2

I'd like to wrap a MyBatScript.bat script inside a MyTest.exe. Then I'd like to invoke MyTest.exe with arguments, thus:

MyTest.exe arg1 arg2

format of passing arguments can be different if need be.

I'd like arg1 and arg2 to be passed on to MyBatScript.bat as %1 and %2 and MyBatScript.bat executed.

How Can I do this?

Thanks!

A: 

Executing a batch file from within your EXE is really just invoking the cmd.exe program with the batch file as a parameter. You could therefor pass any additional parameters this batch file accept along as well.

Assaf Lavie
+1  A: 

This depends entirely on which language you compile the .exe from. Here's an example using C#:

    static void Main(string[] args)
    {
        StringBuilder buildArgs = new StringBuilder();
        foreach(string arg in args)
        {
            buildArgs.Append(arg);
            buildArgs.Append(" ");
        }
        System.Diagnostics.Process.Start(@"C:\MyBatScript.bat", buildArgs.ToString());
    }

This would be the Main function of a ConsoleApplication.

Sean Nyman