CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2001
    Location
    Greece, Athens
    Posts
    1,015

    Running DOS inside C#

    Hi. I need to run an exe using DOS inside my C# programm. I have found some things about running DOS command prompt, but they are about running internal DOS commands like dir,etc. I want to run an exe the syntax of which is iehv /stext c:\\urls.txt and another exe which uses perl and the syntax is perl extract.pl test.htm > test.out. I tried the follwoing code:
    ProcessStartInfo startinfo;
    Process p = null;



    startinfo = new ProcessStartInfo("cmd.exe");


    startinfo.RedirectStandardInput=true;
    //startinfo.RedirectStandardOutput = true;

    // don't exec with shellexecute api
    startinfo.UseShellExecute = false;

    // redirect stdout to this program
    //startinfo.RedirectStandardOutput = true;

    // don't open a cmd prompt window
    //startinfo.CreateNoWindow = true;

    // start cmd prompt, execute command
    p = Process.Start(startinfo);

    p.StandardInput.WriteLine(@"perl extract.pl test.htm > test.out");
    p.StandardInput.WriteLine(@"exit");
    //string output = p.StandardOutput.ReadToEnd();
    //password.Text=output;

    If I use an internal command like dir the command does execute. If I use the commands I need though, I get no output.
    Can anyone help??
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Running DOS inside C#

    It is not that you can just execute Internal Commands, you can execute any EXE/COM file present on your system, provided the path of that file is set-up in Environment Variable (Path)..

    For your code
    Code:
    p.StandardInput.WriteLine(@"perl extract.pl test.htm > test.out");
    Setup up the Path of perl file and then try!
    Or
    Just change the directory to the location where your files exist and then run your Perl compiler/command...
    Something like this
    Code:
    p.StandardInput.WriteLine(@"chdir \MyPerlDirectory");
    And then run the above command...

    HTH

  3. #3
    Join Date
    Jun 2005
    Posts
    3

    Re: Running DOS inside C#

    Also, just FYI, cmd.exe isn't DOS, it's the windows console. DOS doesn't exist in NT/2k/XP anymore. command.com was the DOS command prompt in older versions of windows.

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