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

    Simple command line/console question

    I would like to create a C# program (Console application) that will be equivalent to entering the following lines in a command prompt window.

    chdir C:\Program Files...\R-2.4.0\bin
    R CMD BATCH scrap.R
    DEL .RData

    (it's running the statistical package R in batch mode, scrap.R is an R script.)

    Can anyone help me?

    Thank you

    Another way to manually do this is to make a batch file in the appropriate directory that contains the lines

    R CMD BATCH scrap.r
    DEL .RData

    I've tried Console.WriteLine("...") but it just prints the string rather than executes it.

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Simple command line/console question

    Try to look at System.Diagnostics.Process class. I cannot give you better advice, because I not fully understood the task.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Sep 2007
    Posts
    2

    Re: Simple command line/console question

    Thank you, sorted now

  4. #4
    Join Date
    Aug 2007
    Location
    Minneapolis
    Posts
    155

    Post Re: Simple command line/console question

    Something like this may work
    Code:
    Process process = new Process();
    //Program you want to launch execute etc.
    process.StartInfo.FileName = @"C:\Program Files...\R-2.4.0\bin\R";
    process.StartInfo.Arguments = "CMD BATCH scrap.R";
    //This is important.  Since this is a windows service it will run even though no one is logged in.
    //Therefore there is not desktop available so you better not show any windows dialogs
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.CreateNoWindow = true;
    //We want to redirect the output from the openfiles call to the program
    //Since there won't be any window to display it in
    process.StartInfo.RedirectStandardOutput = true;
    //Create the shell and execute the command
    process.Start();

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