LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2012, 05:35 AM   #1
laks
Member
 
Registered: Feb 2012
Posts: 34

Rep: Reputation: Disabled
Problem with ProcessBuilder in java


Hi All,

I am trying to invoke a command line script from java using ProcessBuilder. Here is how my code looks like.

ProcessBuilder pb = new ProcessBuilder(commandToRun.trim());
pb.directory(new File(fromproddir));
p = pb.start();

But it is not executing the command and fails with the exception"CreateProcess error=123, The filename, directory name, or volume label syntax is incorrect". However, this same command runs perfectly from commandline. It also works from Runtime.exec as given below.

p=Runtime.getRuntime().exec(commandToRun, null,new File(fromproddir));

Any one has any idea when processbuilder throws this error.

PS: commandToRun invokes 7za script to zip a directory.

Thanks,
Lakshmi
 
Old 04-06-2012, 09:22 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
You have to pass the arguments as separate elements in an array/list:
Code:
String directory = getDirectory();
String[] commandToRun = { "7za", "-option", "-option2", directory };
ProcessBuilder pb = new ProcessBuilder(commandToRun);
 
1 members found this post helpful.
Old 04-09-2012, 01:00 AM   #3
laks
Member
 
Registered: Feb 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
Thanks, That worked ...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Java Woes: A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available ... chytraeus Slackware 10 11-27-2010 10:04 AM
and yet another java problem why_linux Linux - Software 3 01-27-2007 10:54 AM
java problem wererabit Linux - Newbie 4 11-16-2006 02:41 AM
JAVA problem madhatter3 Linux - Software 3 01-31-2006 03:37 AM
Java problem davholla Programming 2 09-26-2005 02:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration