calling Java program with complex arguments from Perl script

Experts,

I'm trying to call a Java program from a Perl script.  The java program is kept in a .jar file, and requires that several arguments are specified.  Part of the challenge is that the arguments themselves are complex, multi-word items with spaces that when called from a bash shell, are surrounded by quotation marks.  On a bash command line, it would look like this:

  adolbey$  java -jar MyProgram.jar  work.db  "foo 5 bar == baz"  "alpha 10 beta == gamma"

So the question for me is how can I call this from a Perl script, and do so in a way that groups together the multi-item arguments?  I've seen examples where within the Perl call, the whole thing is just 'java programName arg1 arg2', and is done simply, with something like this:

  system("programName arg1 arg2");

In a case like this, arg1 and arg2 are single tokens, and don't need to be grouped together with quotation marks.  But in the case I'm trying to do, several of the args consist of multiple pieces that need to somehow be kept together.  How would I do this in the context of using 'system()'?

Any help with this would be greatly appreciated.

Thanks!

Andy
aedolbeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
system 'java -jar MyProgram.jar  work.db  "foo 5 bar == baz"  "alpha 10 beta == gamma"';
#or
system 'java', '-jar', 'MyProgram.jar',  'work.db',  "foo 5 bar == baz",  "alpha 10 beta == gamma";
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aedolbeyAuthor Commented:
I should've added one more thing.  I'm trying to do this from a bash command line with:

  adolbey$  perl -e 'java jar...'

How could the two suggestions just given be done in that context?  With perl -e, we're already taking away the possibility of using a single quote with system 'java...'
0
aedolbeyAuthor Commented:
Regarding the last comment I added, about sending in quoted complex, space-separated arguments, the solutions suggested work, even in the context of running the code with <perl -e '[PERL CODE WITH '"foo bar"' HERE]' > in a bash shell.

Thanks for the quick response, ozo.

Andy
0
ozoCommented:
If you want to avoid using ' in order to simplify using ' in -e from command line
system q(java -jar MyProgram.jar  work.db  "foo 5 bar == baz"  "alpha 10 beta == gamma");
or
system "java", "-jar", "MyProgram.jar",  "work.db",  "foo 5 bar == baz",  "alpha 10 beta == gamma";
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.