system(base)
system()所属R语言包:base
Invoke a System Command
调用系统命令
译者:生物统计家园网 机器人LoveR
描述----------Description----------
system invokes the OS command specified by command.
systemcommand指定调用操作系统命令。
用法----------Usage----------
system(command, intern = FALSE,
ignore.stdout = FALSE, ignore.stderr = FALSE,
wait = TRUE, input = NULL, show.output.on.console = TRUE,
minimized = FALSE, invisible = TRUE)
参数----------Arguments----------
参数:command
the system command to be invoked, as a character string.
要调用系统命令,作为一个字符串。
参数:intern
a logical (not NA) which indicates whether to capture the output of the command as an R character vector.
逻辑(不的NA)指示是否捕获命令的输出作为一个R的特征向量。
参数:ignore.stdout, ignore.stderr
a logical (not NA) indicating whether messages written to "stdout" or "stderr" should be ignored.
逻辑(不NA)表示消息是否写入stdout或stderr应该被忽略。
参数:wait
a logical (not NA) indicating whether the R interpreter should wait for the command to finish, or run it asynchronously. This will be ignored (and the interpreter will always wait) if intern = TRUE.
逻辑(不NA)表示的R解释是否应该等待命令完成,或异步运行。这将被忽略(和解释将永远等待)如果intern = TRUE。
参数:input
if a character vector is supplied, this is copied one string per line to a temporary file, and the standard input of command is redirected to the file.
如果提供的特征向量,这是复制一个到一个临时文件,每行字符串,command标准输入重定向到文件。
参数:show.output.on.console
logical (not NA), indicates whether to capture the output of the command and show it on the R console (not used by Rterm, which shows the output in the terminal unless wait is false).
逻辑(而不是NA),指示是否捕获命令的输出,并显示在R控制台(不使用Rterm,这表明在终端输出,除非wait假)。
参数:minimized
logical (not NA), indicates whether a command window should be displayed initially as a minimized window.
逻辑(而不是NA),表示是否应显示一个命令窗口,最初作为一个最小化的窗口。
参数:invisible
logical (not NA), indicates whether a command window should be visible on the screen.
逻辑(而不是NA),表示是否应该是在屏幕上看到一个命令窗口。
Details
详情----------Details----------
command is parsed as a command plus arguments separated by spaces. So if the path to the command (or an argument) contains spaces, it must be quoted e.g. by shQuote. Only double quotes are allowed on Windows: see the examples. (Note: a Windows path name cannot contain a double quote, so we do not need to worry about escaping embedded quotes.)
command被解析命令,加上参数用空格隔开。因此,如果命令(或参数)的路径包含空格,它必须引述如shQuote。只允许在Windows双引号:见的例子。 (注:Windows路径名称不能包含一个双引号,所以我们并不需要担心嵌入引号转义)
command must be an executable (extensions ".exe", ".com") or a batch file (extensions ".cmd" and ".bat"): these extensions are tried in turn if none is supplied.) This means that redirection, pipes, DOS internal commands, ... cannot be used: see shell.
command必须是一个可执行文件(扩展“.exe,.com)或批处理文件(扩展”.cmd和 .bat),这些扩展都试过反过来,如果没有提供),这意味着,重定向,管道,DOS的内部命令,...不能使用:看到shell。
The search path for command may be system-dependent: it will include the R "bin" directory, the working directory and the Windows system directories before PATH.
的搜索command“路径可能依赖系统:包括前binR”PATH目录,工作目录和Windows系统目录。
The ordering of arguments after the first two has changed from time to time: it is recommended to name all arguments after the first.
后,前两个参数的顺序发生了变化,不时建议命名后的第一个所有参数。
There are many pitfalls in using system to ascertain if a command can be run — Sys.which is more suitable.
有使用system,以确定是否可以运行一个命令的许多陷阱 - Sys.which更适合。
值----------Value----------
If intern = TRUE, a character vector giving the output of the command, one line per character string. (Output lines of more than 8095 bytes will be split.) If the command could not be run an R error is generated. Under the Rgui console intern = TRUE also captures stderr unless ignore.stderr = TRUE. If command runs but gives a non-zero exit status this will be reported with a warning.
如果intern = TRUE,给该命令的输出,字符串每行的字符向量。 (超过8095个字节的输出线将被分割。)如果该命令不能运行一个R会产生错误。 Rgui控制台下intern = TRUE也捕捉stderr除非ignore.stderr = TRUE。 command如果运行,但给出了一个非零的退出状态将报告一个警告。
If intern = FALSE, the return value is an error code (0 for success), given the invisible attribute (so needs to be printed explicitly). If the command could not be run for any reason, the value is 127. Otherwise if wait = TRUE the value is the exit status returned by the command, and if wait = FALSE it is 0 (the conventional success value). Some Windows commands return out-of-range status values (e.g. -1) and so only the bottom 16 bits of the value are used.
如果intern = FALSE,返回值是一个错误代码(0成功),由于无形属性(需要明确印)。如果该命令不能运行任何理由,该值是127。否则,如果wait = TRUE值是由命令返回的退出状态,如果wait = FALSE是0(传统的成功值)。有些Windows命令返回范围的状态值(例如-1),所以只有底部16位的值是用来。
If intern = FALSE, wait = TRUE, show.output.on.console = TRUE the "stdout" and "stderr" (unless ignore.stdout = TRUE or ignore.stderr = TRUE) output from a command that is a "console application" should appear in the R console (Rgui) or the window running R (Rterm).
如果intern = FALSE, wait = TRUE, show.output.on.console = TRUEstdout和stderr(除非ignore.stdout = TRUE或ignore.stderr = TRUE)这是一个“控制台命令的输出应用程序应该出现的R控制台(Rgui)或窗口,运行R(Rterm)。
Not all Windows executables properly respect redirection of output, or may only do so from a console application such as Rterm and not from Rgui: for example, "fc.exe" was among these in the past, but we have had more success recently.
并非所有的Windows可执行文件的适当尊重的输出重定向,或只可从控制台应用程序,如Rterm“,而不是从Rgui:例如,fc.exe其中在过去,但我们有更多的成功最近。
命令的相互作用----------Interaction with the command----------
Precisely what is seen by the user depends on the optional parameters, whether Rgui or Rterm is being used, and whether a console command or GUI application is run by the command.
正是用户所看到的取决于可选参数,是否Rgui或Rterm正在使用控制台命令或GUI应用程序是否运行该命令。
By default nothing will be seen in either front-end until the command finishes and the output is displayed.
默认情况下,没有将被视为在任何前端,直到命令完成,并显示输出。
For console commands Rgui will open a new "console", so if invisible = FALSE, a commands window will appear for the duration of the command. For Rterm a separate commands window will appear for console applications only if wait = FALSE and invisible = FALSE.
控制台命令Rgui将打开一个新的“控制台”,所以如果invisible = FALSE,命令窗口会出现命令的持续时间。 Rterm单独的命令窗口会出现控制台应用程序,只有wait = FALSE和invisible = FALSE。
GUI applications will not display in either front-end unless invisible is false.
GUI应用程序将不会显示在任一前端除非invisible是假的。
It is possible to interrupt a running command being waited for from the keyboard (using the Esc key in Rgui or Ctrl-C in Rterm) or from the Rgui menu: this should at least return control to the R console. R will attempt to shut down the process cleanly, but may need to force it to terminate, with the possibility of losing unsaved work, etc.
这是可能中断一个正在运行的命令正在等待从键盘(使用Esc或RguiCtrl-CRterm键)或Rgui菜单:这应该至少控制返回到R控制台。 R将尝试关闭过程干净,但可能需要迫使它终止,可能丢失未保存的工作,等等。
Do not try to run console applications that require user input from Rgui setting intern = TRUE or show.output.on.console = TRUE. They will not work.
不要尝试运行控制台应用程序,需要从Rgui设置intern = TRUE或show.output.on.console = TRUE用户输入。他们将无法正常工作。
Unix和Windows之间的差异----------Differences between Unix and Windows----------
How processes are launched differs fundamentally between Windows and Unix-alike operating systems, as do the higher-level OS functions on which this R function is built. So it should not be surprising that there are many differences between OSes in how system behaves. For the benefit of programmers, the more important ones are summarized in this section.
如何启动进程之间根本不同的Windows的Unix相似的操作系统,做更高级别的操作系统R函数这是内置功能。所以它不应该是不足为奇的操作系统之间有许多分歧,在如何system行为。对于程序员的利益,更重要的是总结本节。
The most important difference is that on a Unix-alike system launches a shell which then runs command. On Windows the command is run directly – use shell for an interface which runs command via a shell (by default the Windows shell cmd.exe, which has many differences from the POSIX shell).
最重要的区别是,第一个Unix相似的system启动一个shell,然后运行command。在Windows上直接运行命令 - 使用shell接口运行command通过一个shell(默认情况下Windows外壳cmd.exe从POSIX shell中,其中有许多差异)。
This means that it cannot be assumed that redirection or piping will work in system (redirection sometimes does, but we have seen cases where it stopped working after a Windows security patch), and system2 (or shell) must be used on Windows.
这意味着它不能假设,重定向或管道将工作system(重定向有时做,但我们所看到的情况下停止工作后,Windows安全补丁),system2(或shell)必须在Windows上使用。
What happens to stdout and stderr when not captured depends on how R is running: Windows batch commands behave like a Unix-alike, but from the Windows GUI they are generally lost. system(intern=TRUE) captures "stderr" when run from the Windows GUI console unless ignore.stderr = TRUE.
会发生什么事stdout和stderr时不捕获取决于R是如何运行的:Windows批处理命令的行为像一个Unix相似,但他们一般都从Windows GUI失去。 system(intern=TRUE)抓住stderr时,从Windows GUI控制台运行,除非ignore.stderr = TRUE。
The behaviour on error is different in subtle ways (and has differed between R versions).
对错误的行为是在微妙的方式不同(已R版本之间的不同)。
The quoting conventions for command differ, but shQuote is a portable interface.
command不同,但shQuote是一个可移植的接口的引用惯例。
Arguments show.output.on.console, minimized, invisible only do something on Windows (and are most relevant to Rgui there).
参数show.output.on.console,minimized,invisible只能做Windows上的东西(以及是Rgui有最相关的)。
参见----------See Also----------
system2.
system2。
shell or shell.exec for a less raw interface.
shell或shell.exec少生接口。
.Platform for platform-specific variables.
.Platform平台特定的变量。
pipe to set up a pipe connection.
pipe设立一个管道连接。
举例----------Examples----------
# launch an editor, wait for it to quit[启动编辑器,等待它退出]
## Not run: system("notepad myfile.txt")[#无法运行系统(“记事本myfile.txt的”)]
# launch your favourite shell:[启动您最喜爱的外壳:]
## Not run: system(Sys.getenv("COMSPEC"))[#不运行:系统(Sys.getenv(“COMSPEC”))]
## Not run: [#无法运行:]
## note the two sets of quotes here:[#注意这里的引号两套:]
system(paste('"c:/Program Files/Mozilla Firefox/firefox.exe"',
'-url cran.r-project.org'), wait = FALSE)
## End(Not run)[#结束(不运行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|