1

考虑两种情况 a) 关闭输出重定向和 b)Rscript 输出重定向到文件 out.txt 两种情况下在 STDOUT 中看到的输出都无法重定向到文件 out.txt 仅在场景 b 中。我在这里遗漏了什么还是 Rscript.exe 特有的?

C:\>C:\\WINDOWS\\system32\\shutdown.exe -t:30 > out.txt

C:\>dir out.txt
 Volume in drive C has no label.
 Volume Serial Number is 3568-1B07

 Directory of C:\

07/18/2012  07:43 PM               841 out.txt
               1 File(s)            841 bytes
               0 Dir(s)  17,618,206,720 bytes free

C:\>G:\\Progra~1\\R\\R-2.14.0\\bin\\Rscript.exe --version > out.txt
R scripting front-end version 2.14.0 (2011-10-31)

C:\>dir out.txt
 Volume in drive C has no label.
 Volume Serial Number is 3568-1B07

 Directory of C:\

07/18/2012  07:44 PM                 0 out.txt
               1 File(s)              0 bytes
               0 Dir(s)  17,618,239,488 bytes free

关于为什么 Rscript.exe 输出没有被重定向到文件 out.txt 的任何想法或解释?也许等待一个非常简单的解释。

感谢您,

4

2 回答 2

1

您不能使用重定向来获取版本信息,但可以将重定向用于实际的 R 命令。例如,如果您的文件a.r中只有一个命令,如下所示1+1

Rscript a.r > out.txt

将显示结果。我认为这与R将版本信息发送到的“输出”有关。我认为它是输出到 STDERR 而不是 STDOUT(或 DOS 中的等效概念),因此重定向不起作用。

于 2012-07-18T14:30:05.700 回答
1

答案很简单。版本信息被写入 STDERR(标准错误流),但您只是重定向 STDOUT(标准输出)。如果你想两者都去文件,然后使用

G:\\Progra~1\\R\\R-2.14.0\\bin\\Rscript.exe --version >out.txt 2>&1
于 2012-07-18T14:30:30.247 回答