为什么使用system()在命令行中加载mysql,而在R中不加载mysql?
我正在尝试将一些sql文件加载到mySql中。在命令行中,它可以工作:为什么使用system()在命令行中加载mysql,而在R中不加载mysql?,r,system,R,System,我正在尝试将一些sql文件加载到mySql中。在命令行中,它可以工作: C:\SomeDirectory\R>mysql -u root -p1234 hat < hat. 2015-10-16T01-10-03 mysql: [Warning] Using a password on the command line interface can be insecure. C:\SomeDirectory\R> Mysql位于系统路径中: > Sys.getenv('
C:\SomeDirectory\R>mysql -u root -p1234 hat < hat.
2015-10-16T01-10-03
mysql: [Warning] Using a password on the command line interface can be insecure.
C:\SomeDirectory\R>
Mysql位于系统路径中:
> Sys.getenv('PATH')
[1] "C:\\Program Files\\R\\R-3.2.1\\bin\\x64;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files\\SASHome\\Secure\\ccme4;C:\\Program Files\\SASHome\\x86\\Secure\\ccme4;C:\\Windows\\system32\\config\\systemprofile\\.dnx\\bin;C:\\Program Files\\Microsoft DNX\\Dnvm\\;C:\\Program Files\\MySQL\\MySQL Server 5.7\\bin;C:\\Program Files (x86)\\Skype\\Phone\\;C:\\Program Files\\7-Zip"
有人知道有什么问题吗?谢谢你的帮助。谢谢
更新:
shell
工作正常
> command1
[1] "mysql -u root -p1234 hat < hat.2015-10-16T01-10-03"
> shell(command1)
mysql: [Warning] Using a password on the command line interface can be insecure.
由于您使用的是Windows,因此无法通过
系统
调用shell命令,这与您在控制台上调用shell命令的方式相同
有关详细信息,请阅读文档。特别是,它说:
这意味着不能假定重定向或
管道将在系统中工作(重定向有时会工作,但
我们已经看到过这样的情况,它在一个窗口关闭后停止工作
安全补丁)和system2
(或shell
)必须在上使用
窗户
因此,简而言之,解决方案是:使用system2
,或者不使用重定向(您可以将标准输入和输出流指定为system
的单独命令)。Hi@Konrad Rudolph感谢您的帮助!抱歉这么晚才回复,我正在准备面试。我不理解重定向的意思。。你能解释一下吗?我阅读了文档,发现在UNIX中,命令
是通过shell
运行的,但在Win中不是。因此,一些需要shell
的命令在Win中不起作用,然后我们需要system2
或shell
。我尝试了shell
,它成功了!无法使system2
工作,尽管b/c不知道哪个部分是参数
。你能帮忙吗。请参阅OP中的更新
> command1
[1] "mysql -u root -p1234 hat < hat.2015-10-16T01-10-03"
> shell(command1)
mysql: [Warning] Using a password on the command line interface can be insecure.
> system2('mysql -u root -p1234 hat', args = "hat.2015-10-16T01-10-03")
Warning message:
running command '"mysql -u root -p1234 hat" hat.2015-10-16T01-10-03' had status 127
> system2('mysql -u root -p1234', args = 'hat < hat.2015-10-16T01-10-03')
Warning message:
running command '"mysql -u root -p1234" hat < hat.2015-10-16T01-10-03' had status 127