-
September 20th, 2007, 05:58 AM
#1
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.
-
September 20th, 2007, 07:34 AM
#2
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.
-
September 20th, 2007, 09:06 AM
#3
Re: Simple command line/console question
-
September 20th, 2007, 05:13 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|