CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2010
    Posts
    2

    Problem with Process and file .bat

    Hey Guys,

    I have an problem with one program that I am developing. My issue is this.
    I have one file bat with several commands inside. And this file bat HAVE TO run with Console2(VS2008 Prompt), is not allowed run with cmd.exe.

    Then, I want develop an program with C#, that call Console2 and after that call the file bat, to run the file bat inside of the Console2.

    My problem is that my program in C# get call the console2, but don´t get call the file bat to run with Console2.

    What is happen with my program, anyone can help me.

    Following one piece of my code

    Process proc = new Process();
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardOutput = true;

    proc.StartInfo.FileName = "C:\\Program Files\\console2\\console.exe";
    proc.StartInfo.Arguments = "teste.bat";
    proc.Start();
    proc.WaitForExit();


    Thanks

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Problem with Process and file .bat

    The VS command prompt is simply a cmd shell with various environment variables set (this is done with the vcvarsall.bat).

    You can replicate the same environment by opening up a cmd.exe process and set the same variables as what is in the vcvarsall.bat file.

  3. #3
    Join Date
    Dec 2010
    Posts
    2

    Re: Problem with Process and file .bat

    How I do this?


    When I use cmd.exe in my program c#, the cmd.exe get call the bat file.

    But when I change the "FileName" to Console.exe, my program don´t get call the bat file.
    My bat file must run with Console.exe and don´t with cmd.exe.
    Just with Console.exe.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Problem with Process and file .bat

    When you say " is not allowed run with cmd.exe.", what do you mean?

    If I understand what you are doing, it sounds like you need to setup the environment variables for the console window that you launch.

  5. #5
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Problem with Process and file .bat

    The same comment as Arjay already has provided but maybe a little more explicit.

    Since cmd.exe starts without any problems there's a good chance that you need some extra parameters when starting console.exe. Check what's done (properties) when you start console.exe from the start menu.

    Is it possible to start console.exe (with path) from cmd.exe?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  6. #6
    Join Date
    Dec 2010
    Posts
    12

    Re: Problem with Process and file .bat

    I guess there is another way to specify the arguments, may be some kind of identifier to specify the filename to be executed by console2.exe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured