Skip to main content
Oct 14, 2016 9:05 AM UTC
Question

How to execute multiple commands one by one on command prompt using JAVA.

Hi,

i have used,

Process p = Runtime.getRuntime().exec("cmd /c \"start sqlplus system/manager && CREATE OR REPLACE DIRECTORY export_dir AS 'E:\';\"");

application connected to oracle database successfully using command sqlplus system/manager. but second command CREATE OR REPLACE DIRECTORY export_dir AS 'E:\';

does not work as shown in Image attached. Plz let me know how to execute multiple commands on cmd.exe one by one . Please check syntax to run multiple commands in Process p = Runtime.getRuntime().exec("cmd /c \"start sqlplus system/manager && CREATE OR REPLACE DIRECTORY export_dir AS 'E:\';\"");

Thanks

Manoj

3 replies

manpatilAuthor
Oct 14, 2016 9:07 AM UTC

image.jpg

Oct 17, 2016 6:59 AM UTC

Hi Manoj,

why do you try in java to start sqlplus from the command windows? Wouldn't it be easier to call sqlplus directly from java?

I suppose you'll have to group your 2 main commands, so the start apply to them:

Process p = Runtime.getRuntime().exec("cmd /c \"start (sqlplus system/manager && CREATE OR REPLACE DIRECTORY export_dir AS 'E:\';) \"");

Loïc

Oct 28, 2016 5:56 AM UTC

Hello,

this is a new feature in java 9 and is not released till now.

Ciao

Leo