java command containing classpath in quotes on unix

N

Nishi Bhonsle

Hi:

The following java command (containing the classpath to the Backup.class file in quotes) runs successfully on windows but not on Unix
The version of java used is 1.3.1_02, I even tried with a later version 1.4.1 but it does not work. Modifying the command to not to include quotes runs successfully on Unix as well. How can I make the command with the classpath in quotes to run successfully on all platforms?

C:\javahome\jdk\bin\java -classpath "C:\temp" Backup C:\tempnew

Thanks.
 
S

Sudsy

Nishi said:
Hi:

The following java command (containing the classpath to the
Backup.class file in quotes) runs successfully on windows but not on Unix
The version of java used is 1.3.1_02, I even tried with a later version
1.4.1 but it does not work. Modifying the command to not to include
quotes runs successfully on Unix as well. How can I make the command
with the classpath in quotes to run successfully on all platforms?

C:\javahome\jdk\bin\java -classpath "C:\temp" Backup C:\tempnew

You can't, at least not easily. There are some fundamental differences
between the systems:
- windows uses drive letters, *nix embodies no such concept
- windows uses backslash as path separator, *nix uses forward slash
- windows uses a semicolon as classpath separator, *nix uses that
character as a command separator (it uses colon as the classpath
separator)
It's that last one which will bite you soonest. Better to create a BAT
file for windows and a Bourne shell (sh) script for *nix. Sorry.

-
 
N

Nishi Bhonsle

Sudsy said:
You can't, at least not easily. There are some fundamental differences
between the systems:
- windows uses drive letters, *nix embodies no such concept
- windows uses backslash as path separator, *nix uses forward slash
- windows uses a semicolon as classpath separator, *nix uses that
character as a command separator (it uses colon as the classpath
separator)
It's that last one which will bite you soonest. Better to create a BAT
file for windows and a Bourne shell (sh) script for *nix. Sorry.

I tried using the correct slashes and the correct classpath separator too but it still did not work.
Is creating a shell script the only option even using the right syntax?
 
S

Sudsy

Nishi said:
I tried using the correct slashes and the correct classpath separator too but it still did not work.
Is creating a shell script the only option even using the right syntax?

Since you haven't shared the actual commands, I'd be inclined to
respond in the positive. Care to post the EXACT commands and how
you've packaged them?
 
N

Nishi Bhonsle

Sudsy said:
Since you haven't shared the actual commands, I'd be inclined to
respond in the positive. Care to post the EXACT commands and how
you've packaged them?

Consider I am using the java from a dir called /home/jdk/bin and the class that needs to be run is under /home/test directory. This class is accepting one other argument which is the directory /home/realDir, then my command is

/home/jdk/bin/java -classpath "/home/test" Backup /home/realDir


If I run the above command without the quotes, it runs fine ie
/home/jdk/bin/java -classpath /home/test Backup /home/realDir

But I would like to use quotes because sometimes the class could be under a directory whose name has spaces in it such as "test case", in that case, the command without quotes would fail.
 
S

Sudsy

Nishi said:
Sudsy wrote:




Consider I am using the java from a dir called /home/jdk/bin and the class that needs to be run is under /home/test directory. This class is accepting one other argument which is the directory /home/realDir, then my command is

/home/jdk/bin/java -classpath "/home/test" Backup /home/realDir


If I run the above command without the quotes, it runs fine ie
/home/jdk/bin/java -classpath /home/test Backup /home/realDir

But I would like to use quotes because sometimes the class could be under a directory whose name has spaces in it such as "test case", in that case, the command without quotes would fail.

Hard to tell where the problem is since java shouldn't even SEE the
quotes: they should be gobbled up by the shell. What shell are you
using?
 
N

Nishi Bhonsle

Sudsy said:
Hard to tell where the problem is since java shouldn't even SEE the
quotes: they should be gobbled up by the shell. What shell are you
using?

tcsh.
Looks like I need to use Korn shell to run the java command successfully(I just changed the shell to ksh and it worked fine). But since I am spawning this command inside another program say A.java I will have to explicitly set the shell before running A.java. Hopefully the command can see the shell settings.
Is there any other way around besides changing the shell?
Thanks.
 
G

Gordon Beaton

Looks like I need to use Korn shell to run the java command
successfully(I just changed the shell to ksh and it worked fine).
But since I am spawning this command inside another program say
A.java I will have to explicitly set the shell before running
A.java. Hopefully the command can see the shell settings. Is there
any other way around besides changing the shell?

It sounds like you are using Runtime.exec(String) in order to execute
the command, in which case no shell is used at all (unless you
explicitly included the shell as part of the command line itself).

Use Runtime.exec(String[]) instead, and don't include any quotes in
your command. With this version of exec(), each argument is specified
as a separate String that will not be further processed by the
StringTokenizer that Runtime.exec(String) uses.

If my assumption is incorrect, please be more specific about just how
you spawn this command.

/gordon
 
S

Sudsy

Nishi Bhonsle wrote:
tcsh.
Looks like I need to use Korn shell to run the java command successfully(I just changed the shell to ksh and it worked fine). But since I am spawning this command inside another program say A.java I will have to explicitly set the shell before running A.java. Hopefully the command can see the shell settings.
Is there any other way around besides changing the shell?
Thanks.

Try something like this:

Process p = Runtime.getRuntime().exec(
new String[] { "/bin/ksh", ... } );

where your other arguments replace the elipses.
Here's an example:

Process p = Runtime.getRuntime().exec( new String[] { "/bin/ksh", "-c",
"echo hello" } );

Then you have to get the stdout and stderr InputStreams, etc.
If you're unfamiliar with that part then post again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top