0

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.

2
  • what error you are getting? Commented Aug 18, 2014 at 8:49
  • 4
    That's not executing an sql command. That's typing out a file. Commented Aug 18, 2014 at 8:50

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Output can simply be redirected to a new file using > I guess, there is no such --result-file attribute for type command I think!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.