Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Executing a parameterised bat file in C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 115
    Comment on it

    In one of my recent projects, I had to execute a bat file which was expecting one argument before execution. Content of bat file was like this :

    "%~dp0phantomjs.exe" "%~dp0..\examples\rasterize.js" "%1" "%~dp0twingle.jpg"

    If you Analise the above code then you will see that it is expecting the parameter "%1" so i had to pass this parameter using C# code. Here is the method that solved my purpose

     Void  ExecBatFile()
            {
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    string filePath = Your File Path
                    proc.StartInfo.FileName = filePath;
                    proc.StartInfo.Arguments = String.Format("{0}",http://findnerd.com");//Passing arguments for the first parameter in bat file
                    proc.Start();//Starts the Project
    proc.WaitForExit();//Makes the process wait till the bat file execution is not     completed
            }
    

    Using the above method, I passed "http://findnerd.com" as parameter value for first argument. This way i was able to execute the bat file with parameter

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: