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.
[638 byte] By [CKeef] at [2007-11-20 10:52:31]
# 1 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.
boudino at 2007-11-9 11:36:06 >
# 2 Re: Simple command line/console question
Thank you, sorted now
CKeef at 2007-11-9 11:37:06 >
# 3 Re: Simple command line/console question
Something like this may workProcess 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();
trenches at 2007-11-9 11:38:04 >