简体   繁体   English

无法在Java中执行命令

[英]Can't execute command in java

I want one of these commands to be executed. 我希望执行这些命令之一。 I can't do it in java. 我在Java中无法做到。 Commands are: 命令是:

type table1.sql, table2.sql, table3.sql > sBackup.sql
type *.sql > allinone.sql  --[Make a backup for all file in the folder]
copy *.sql merged.sql

I tried this: 我尝试了这个:

String command = "type " + "*.sql" + " --result-file=" + "c:\\sBackup.sql";
Runtime.getRuntime().exec(command);

Your valuable insight is highly appreciated. 非常感谢您的宝贵见解。 Thank you. 谢谢。

type and copy are both built-ins in the Windows command shell, not actual programs you can execute. typecopy都是Windows命令外壳程序中的内置程序,不是可以执行的实际程序。 To execute them, you execute a command shell and provide the command as an argument after a /C : 要执行它们,您可以执行命令外壳并在/C之后提供命令作为参数:

String command = "cmd.exe /C type " + "*.sql" + " --result-file=" + "c:\\sBackup.sql";
Runtime.getRuntime().exec(command);

...but I'll just note that I don't think type has a --result-file argument. ...但我只是要注意,我认为type没有--result-file参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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