Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2007, 01:33 PM
Registered User
 
Join Date: Feb 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass multiple args to bat file from console app

From a C# console application , I want to invoke a .bat file which will copy files from the source folder to the destination folder. The two parameters source and destination folder name will be passed from the console application to the bat file. How could this be achieved.
Any sample code provided would be appreciated.
 
Old February 9th, 2007, 03:04 PM
Authorized User
 
Join Date: Oct 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to evandro.paula
Default

Let's suppose you have got the following (BAT) file:

test.bat
--------
echo off
echo Name: %1
echo Birth: %2

To invoke execution to this file passing arguments, you can use System.Diagnostics.ProcessStartInfo class and Arguments property. Take a look at the sample (console application) below:

    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.ProcessStartInfo psi= new System.Diagnostics.ProcessStartInfo(@"c:\test.bat" );
            psi.Arguments = "Evandro 09/08/1977";
            psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
            psi.UseShellExecute = false;

            System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
            p.Start();
            p.Kill();

            System.Console.Read();
        }
    }

Regards.
 
Old February 9th, 2007, 03:38 PM
Registered User
 
Join Date: Feb 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, but during execution, an error message 'access is denied' is thrown.






Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ console app barrytn Visual C++ 2005 2 July 11th, 2008 02:11 AM
Schedule a console app hamilton General .NET 1 January 5th, 2007 10:50 AM
is making console app using C# a waste rahulmballal BOOK: Professional C#, 2nd and 3rd Editions 0 January 25th, 2005 11:13 AM
invisible console app asmotritsky Visual C++ 1 November 25th, 2004 03:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.