使用 R 的系统将多个参数传递给可执行文件

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

我读了一些其他的 answer 但这看起来有点不同:

coddinggame_DEBUG 接受多个参数。要在 bash 中使用固定参数调用它,我会这样做:

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

这行得通。 bash 答案:

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

(无警告且均值和 Sd 计算正确)

如果我尝试通过 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)

我得到:

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

例如第二个参数 ('1') 未正确传递,导致代码停在那里。

这个有效:

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)