user189035
user189035

Reputation: 5789

Using R's System to pass multiple arguments to an executable

I have read a bit some other answer but this seems a bit different:

coddinggame_DEBUG takes several arguments. To invoke it in bash with fixed arguments I do:

cd /superdirectory/
./codinggame_DDEBUG <<'EOF'
testCases01.txt
1
4
EOF

and this works. The bash answers:

Enter File name (with extention): Enter seed (unsigned integer): Enter Line Number: Mean Sample:23.3821  Sd Sample:6.19504

(no warning and the Mean and Sd are computed correctly)

If I try to achieve the same through R:

x<-paste0('cd /superdirectory/  \n
./codinggame_DDEBUG <<"EOF"     \n
testCases01.txt                 \n
1                               \n
4                               \n
EOF                             \n
echo done')
cat(x)
system(x)

I get:

Enter File name (with extention): Enter seed (unsigned integer): Warning:1

e.g. The second argument ('1') is not passed properly which causes the code to stop there.

Upvotes: 1

Views: 119

Answers (1)

user189035
user189035

Reputation: 5789

This works:

x<-paste0('cd /superdirectory/  \n
    >input.txt echo testCases01.txt                     \n
    >>input.txt echo 1                          \n
    >>input.txt echo 4                      \n
    ./codinggame_DDEBUG <input.txt                  \n
    echo done')
    cat(x)

system(x)

Upvotes: 1

Related Questions