Illya
Illya

Reputation: 263

Running a .bat file from R - had status 2

I am trying to run a .bat file, which does run perfectly when I double click in it (Windows OS), but fails when I try to run it in R

 com <- "C:\\SASLocal\\RUN3614\\56a8c11b-84b2-4af7-a155-01190936b1c1\\M1_superGOtest.bat"

 system(com)

I am getting back a message of had status 2

Just an FYI, this triggers a SAS program, which I need to run in SAS as it is for comparison purposes between SAS and R.

Upvotes: 0

Views: 1927

Answers (1)

Parfait
Parfait

Reputation: 107567

In Windows, to run batch files from command line you need to call a command line interpreter, Command Prompt or PowerShell, passing batch file as an argument.

A .bat script by itself is like an .R script and does not do anything until an executable runs it (i.e., Rscript.exe, R.exe, Rcmd.exe, Rterm.exe) and in this case, cmd.exe and powershell.exe:

# COMMAND PROMPT
system('cmd /c "C:\\SASLocal\\RUN3614\\56a8c11b-84b2-4af7-a155-01190936b1c1\\M1_superGOtest.bat"')

# POWERSHELL
system('powershell -c & "\'C:\\SASLocal\\RUN3614\\56a8c11b-84b2-4af7-a155-01190936b1c1\\M1_superGOtest.bat\'"')

Upvotes: 1

Related Questions