permaculture playing cards*
The moose likes Beginning Java and the fly likes What does @ do, as in: c:\java -classpath % c:\blalba\... A.B.C.Class %@ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What does @ do, as in: c:\java -classpath % c:\blalba\... A.B.C.Class %@" Watch "What does @ do, as in: c:\java -classpath % c:\blalba\... A.B.C.Class %@" New topic
Author

What does @ do, as in: c:\java -classpath % c:\blalba\... A.B.C.Class %@

Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Im tryig to run the following line in DOS (org. from a shell script):



This results in:
Exception in thread main java.lang.ArrayIndexOutOfBound: 2
at ....
at ....

If I remove the '@' at the end of the line the program doesn't run but says
something like:
"Usage: bla bla bla"

Any ideas?

Could it be, that @ is a unix symbol, and I need the equivalent in DOS?
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
I'm familiar with the -D switch and the -classpath switch, but what are the --jms and --jboss switches for? I can't find any sample code anywhere that uses switches like that.

I apologize for being of no help... that just struck me as an odd usage. I can wage a guess as to the issue you are having though (and I am pretty sure that you have already reached the same conclusion), but it looks to me like there is an error in your code. When you remove the @,the command is not even being executed (thus the usage warning).
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi Chad,

When I include the '@' at the end of "java -Dprogram ..... "
I get the following message:



If '@' is included the application doesn't run, and if I remove it I get an
ArrayIndexOutOfBound exception. I can not access and modify the original
code btw. I just dont know what '@' is... as explained earlier, the line
has been "stolen" from a shell script, and im now trying to get it to work
on DOS.

Any ideas?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18500
    
  40

Originally posted by Svend Rost:
If '@' is included the application doesn't run, and if I remove it I get an
ArrayIndexOutOfBound exception. I can not access and modify the original
code btw. I just dont know what '@' is... as explained earlier, the line
has been "stolen" from a shell script, and im now trying to get it to work
on DOS.

Any ideas?


I don't think that "%@" has any meaning to a DOS command prompt. But if it was from a shellscript, and it was originally "$@", then it is simply the parameters from the shellscript -- the parameters to the shellscript are used to replace the "$@".

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Originally posted by Henry Wong:


I don't think that "%@" has any meaning to a DOS command prompt. But if it was from a shellscript, and it was originally "$@", then it is simply the parameters from the shellscript -- the parameters to the shellscript are used to replace the "$@".

Henry


Thanks for replying Henry,

Yes, it originally was $@ in the shell script (which I then changed to %@ because % is used instead of $ (I've been told)). I dont understand what
your saying at the end? What should I do?


I've been doing a bit of testing. I "stand" in folder c:\foo\bar which
contains a file (Abc.cba) which should be used as input parameter. The application
I need to run (BlahRunner) is located in c:\XX\ (this folder is added to
the my windows classpath btw).

I have a bat file in c:\XX called runner.bar, if it contains:

and I do the following. c:\foo\bar\> runner Abc.cba I get:
Usage:
BlahRunner [--jms|--rmi] <filename>.<extension> [tracefile]

When I look at the output in the DOS window, i.e. what's being executed I
see the following:


If on the other hand I run the bat file without the @, i.e. this is in the
bat file:

I get an exception: ArrayIndexOutOfBounds: 2 BUT when I look at the output
in the dos window it looks like the output I got earlier, i.e. no Abc.cba

Finally I try to insert the file name in the bat file:

and when I run it: c:\foo\bar\> runner
I see that everything seems to gets executed:

But I get an exception: OutOfBoundsException: -1


Anyone got any ideas? when I run the script, i.e. runner.sh Abc.cba
I get the following output in cygwin:
/foo/bar/> java -Dprogram.name=MyProgram -classpath c:\XX\File1;..;c:\XX\FileN A.B.C.BlahRunner Abc.cba --jms --jboss


Thanks in advance,

Svend
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I believe that the DOS equivalent to $@ is %1 %2 %3 %4 %5 %6 %7 %8 %9, as in

java -DX=y -cp XXX ClassName --jms --whatever %1 %2 %3 %4 %5 %6 %7 %8 %9

Of course Henry's right about what it does: it expands to all the arguments from the command line of the script. The DOS equivalent just does this explicitly for the first 9 parameters.

Note, for those that may not have caught on, that --jms and --whatever are command-line arguments to the class, not to Java itself.


[Jess in Action][AskingGoodQuestions]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18500
    
  40

Another option is to use "%*" which expands to all of the parameters.

BTW, the DOS command prompt is actually really cool -- in terms of parameter handling, that is. You can actually asked DOS to treat the parameter as a file and replace it with related data instead.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does @ do, as in: c:\java -classpath % c:\blalba\... A.B.C.Class %@
 
Similar Threads
Pattern & Matcher - how to get any combination?
Converting shell script to a batch file
OpenEJB + JUnit + Ant
How To Compile Using Command Line
Exception in thread "main" java.