How do I use Linux commands sequence in my Java classes
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   abhay_prajapati
Posted On:   Thursday, April 15, 2004 11:36 AM

i m executing simple commands through java, Process process = Runtime.getRuntime().exec("...command..."); but now, i want to execute commands in sequence, for example: if we run " mysql " command another prompt will come in konsole, mysql> then i want to run " create database test; " so tht another database is created, mysql>create database test; is it possible to run command this way ? if i have the object of Process then can i give more commands in tht object and also no new process should be created, everything should be in one process only.    More>>


i m executing simple commands through java,
Process process = Runtime.getRuntime().exec("...command...");



but now, i want to execute commands in sequence,


for example: if we run " mysql " command another prompt will come in konsole,


mysql>


then i want to run " create database test; "
so tht another database is created,


mysql>create database test;


is it possible to run command this way ?


if i have the object of Process then can i give more commands in tht object and also no new process should be created, everything should be in one process only.

   <<Less

Re: How do I use Linux commands sequence in my Java classes

Posted By:   joe_user  
Posted On:   Sunday, May 23, 2004 02:09 AM

For Oracle, I have a script that looks like this (to start the database).


---- cut ----


$ORACLE_HOME/bin/lsnrctl start

$ORACLE_HOME/bin/sqlplus "/as sysdba" << __EOF
startup;
exit;
__EOF

---- cut ----


The important part is the sqlplus thing, the '<< __EOF __EOF' surrounds the commands to be executed by sqlplus after its invocation. This is UNIX rather than java, though.


Perhaps mysql allows a similar construct.


What I'd really do in a situation like yours, is to detach the sql part from my program (seems that you want to do general purpose stuff) and stick it into a web services or other process.

Re: How do I use Linux commands sequence in my Java classes

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, April 16, 2004 07:06 AM

Write a script, and execute the script (a shellscript, and/or a sql script for mysql)

About | Sitemap | Contact