how do i run bash command from java application

siddharthkool
siddharthkool used Ask the Experts™
on
my cmdstr:- from java application does not work

"/bin/bash -c 'cd \"/cs/clt/rh52/\"; svn export http://svn.abc.com/svn/cs/qa/db2 \"cs/clt/rh52\" --force'";
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
what are you using to execute this. is it Runtime.getruntime?

you are closing double quotes in the middle so could that have something to do with it?

Mick BarryJava Developer
Top Expert 2010

Commented:
be easier to create a shell script and use runtime.exec to call the script
also make sure you are reading any output
http://helpdesk.objects.com.au/java/runtime-exec-locks-up

Author

Commented:
yes im using Runtime.getruntime to execute this cmdstr. This is the shell command trying to execute through click of a button
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Top Expert 2006

Commented:
I did think about a shell script first, create one dynamically then delete once run. Ive done this in the past. Makes life easier. But will not take credit for it as it has already been mentioned by objects.

I know the double quotes have been escaped but have you seen the generated line to see what it actually looks like?

perhaps write that line to a text file then inspect

I guess you would expect to see something like this


/bin/bash -c 'cd "/cs/clt/rh52/"; svn export http://svn.abc.com/svn/cs/qa/db2 "cs/clt/rh52" --force';

If you ran this in the shell, does it work? if not then maybe fix errors and try to apply via code
Mick BarryJava Developer
Top Expert 2010

Commented:
you should also use a string array instead of a single string for your command

Author

Commented:
@rockiroads: i tried it does not work.   is the cmdstr right, the way im doin.....
Java Developer
Top Expert 2010
Commented:
rt.exec(newString[] { "/bin/bash", "-c", "cd /cs/clt/rh52/; svn export http://svn.abc.com/svn/cs/qa/db2 cs/clt/rh52 --force"});
Top Expert 2006

Commented:
I wasnt sure about the double quotes. I dont think you need them.

Is the reason for the single quotes because you got multiple commands? I dont have access to a shell at the moment so cannot verify. Trial/error for you to get it working on the shell first.

objects, can you give an example on how you suggest using the string array?
Top Expert 2006

Commented:
lol, objects your post wasnt there whilst I was typing.

Author

Commented:
object u rock

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial