Multiple shell commands in Windows

r

Solution

I'm on Linux and this works for me:

system("cd ..;ls")

in navigating to the previous directory and running ls/dir there. In your case, on Windows, this apparently works:

shell("cd C: & dir")

or to get the output as a character vector:

`shell("cd C: & dir", intern=T)` and on Linux: `system("cd ..; ls", intern=T)`

Problem

I'm trying to replicate a shell command in R and cannot figure out how to string commands together. This just returns the contents of the working folder (`system()` fails for some reason): ``` > shell("dir") Volume info .. Directory of E:\Documents\R contents are listed.. ``` Now lets try and navigate to C drive and run `dir` (without using the obvious `dir C:`).. ``` > shell("cd C:") C:\ > shell("dir") Volume in drive E is GT etc.. ``` So it seems commands can't be entered separately as the shell doesn't remember the working directory. So.. ``` > (cmd = "cd C: + dir") [1] "cd C:\ndir" > shell(cmd) C:\ ``` No luck as the C: folders are not reported. Other methods I've tried also fail. Grateful for any ideas.

Original source