简体   繁体   中英

How do I include a variable file name in a system() function to call Windows commands

This is likely a stupid question but I have not found a work around (at least in anything I have searched for, though I might just not be using the right search parameters.)

I want to call an executable in Windows, and send a file to it (in this case a Blaise man file), the name of which is variable in my script.

So, for example, I have

x<-2
myfile<-c(paste("FileNumber",x,".man", sep="")
system("myapp.exe" myfile)

But I simply get

Error: unexpected symbol in "system("myapp.exe" myfile"

as if the command is not recognizing the object as myfile, instead taking "myfile" as literal text.

I tried using a paste function to create a whole line command, but that also did not work.

The system command will not concatenate the string and the myfile object together, you have to do it yourself.

So, try this instead:

x<-2
myfile<-c(paste("FileNumber",x,".man", sep=""))
cmd <- paste("myapp.exe", myfile)
system(cmd)

Or just:

x<-2
system(paste("myapp.exe", c(paste("FileNumber",x,".man", sep=""))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM