Xerox Shah
Xerox Shah

Reputation: 3

Can't execute command in java

I want one of these commands to be executed. I can't do it in 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.

Upvotes: 0

Views: 125

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075537

type and copy are both built-ins in the Windows command shell, not actual programs you can execute. To execute them, you execute a command shell and provide the command as an argument after a /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.

Upvotes: 2

Related Questions