Reputation: 21
In windows 7 at run prompt, this command succeeds in launching the .exe with the the optional input file "test2.dat"
c:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe k:/Project/EPA.Pb.IEUBK/batch.io/input/test2.dat
I want to do the same thing from within R.
In R, this command succeeds in launching the same .exe
shell.exec("c:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe")
But I've been unable to find a solution within R that will launch the .exe with the optional input file. I've looked at shell()
, shell.exec()
and system()
but I could not find the right incantation that will pass the optional input file to the .exe.
Any thoughts?
Upvotes: 2
Views: 6855
Reputation: 1327
Typing into the normal cmd.exe
-promt a command including spaces as in C:\Program Files (x86)\...
does not work:
The Command "C:\Program" could not be found.
Typing in the same command with double quotes does work. E.g.:
"C:\Program Files (x86)\7-Zip\7z" -a ...
To get it to work in R, you can use single quotes ('
) to mark a R string and double quotes ("
) for the command itself. Actually, you have the possibility of three different quotes to use (backtick is the third one `
, see here for more information). Or you use escapes as mentioned in the answer of @Frank.
system('"C:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe" k:/Project/EPA.Pb.IEUBK/batch.io/input/test2.dat')
In addition ?system
mentions not just to use shell
in windows but also system2
as alternative:
...This means that it cannot be assumed that redirection or piping will work in
system
(redirection sometimes does, but we have seen cases where it stopped working after a Windows security patch), andsystem2
(orshell
) must be used on Windows.
But for me system
works totally fine not using piping or redirection.
Upvotes: 2
Reputation: 300
shell.exec() is used for opening files associated in your OS.
in your case, the shell command should be preferred but you need to take care of spaces in your filenames and mask quotaion marks.
Please try:
shell("\"c:/Program Files (x86)/IEUBKwin1_1 Build11/IEUBKwin32.exe\" k:/Project/EPA.Pb.IEUBK/batch.io/input/test2.dat")
Upvotes: 1