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.
Gerald Schneider
17.8k10 gold badges64 silver badges79 bronze badges
-
what error you are getting?Vishrant– Vishrant2014年08月18日 08:49:18 +00:00Commented Aug 18, 2014 at 8:49
-
4That's not executing an sql command. That's typing out a file.T.J. Crowder– T.J. Crowder2014年08月18日 08:50:27 +00:00Commented Aug 18, 2014 at 8:50
1 Answer 1
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.
answered Aug 18, 2014 at 8:52
T.J. Crowder
1.1m201 gold badges2k silver badges2k bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Am_I_Helpful
Output can simply be redirected to a new file using
> I guess, there is no such --result-file attribute for type command I think!lang-java