>From C, that is not how you redirect stdin, stdout (and you have forgotten
to redirect stderr). I'll leave you to fathom that out (but as you are on
Windows, the R sources should give you many useful clues). (Note that you
do actually need a stdin and stdout to redirect, and a Windows application
does not necessarily have them set up.)
On Tue, 20 May 2003 alkatz at post.tau.ac.il wrote:
> Hello R-people,
>
> I have the following problem :
>
> In order to run R script from DOS prompt in BATCH mode and pass it some
> parameters I do the following :
>
>
> Rterm --slave --no-save --no-restore <args.R> args.out ARG1=1 ARG2=2
That is actually <args.R >args.out: whether your form works depends on the
OS and shell. The effect is to redirect stdin/stdout and is done either
by the shell or by the C initialization code.
> It works fine :
> the result is that the script args.R is isexecuted. Sys.getenv() sees the
> arguments ARG1 and ARG2, and the R creates output file args.out
>
>
> Now I want to be able to call the same command from C application :
>
>
> #include <conio.h>
> #include <process.h>
> #include <string.h>
>
>
> void main()
> {
> char *args[10], prog[80];
> int ch;
>
> strcpy(prog, "C:\\Program Files\\R\\RBase\\bin\\Rterm.exe ");
>
> /* Arguments to Rterm.exe */
> args[0] = "--slave";
> args[1] = "--no-save";
> args[2] = "--no-restore";
> args[3] = "<args.R>";
> args[4] = "args.out";
> args[5] = "ARG1=1";
> args[6] = "ARG2=2";
> args[7] = NULL;
>
>
> _execl( prog, args[0], args[1], args[2], args[3], args[4], args[5],
args[6],
> NULL);
> }
>
>
> Rterm starts, but writes to output :
>
> ARGUMENT '<args.R>' __ignored__
> ARGUMENT 'args.out' __ignored__
>
>
> Command Sys.getenv("ARG1") returns correct result => R sees
the rest of the
> arguments.
>
> I tryed to type args[3] = "args.R" - without <> it does not
help.
>
> Does enyone know what might be my problem ??
>
> Thanks,
> Alex.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595