Solved

run.bat file

Posted on 2003-12-07
7
824 Views
Last Modified: 2010-03-31
I am having weird error. I am passing two args when I run this program.
args[1] is: http://webdev.apl.jhu.edu/%7Emed/summer03/homework/05LibrarySwing.html
However, when I put this url in run.bat file like this:

java <program>  <path> http://webdev.apl.jhu.edu/%7Emed/summer03/homework/05LibrarySwing.html

args[1] comes into main without "%7", and that is why my program doesn't work.
Another word, System.out.println("args[1] " + args[1] ); just print http://webdev.apl.jhu.edu/Emed/summer03/homework/05LibrarySwing.html
Of course, run.bat file is excutable file.

Why is that?
-----------------

  public static void main(String[] args) throws CrawlerException {

    checkUsage(args);
    //final String LINE_SEPARATOR = System.getProperty("line.separator");
    //StringBuffer buffy = new StringBuffer("");

    try{
      System.out.println("args[1] " + args[1] );
      URL url = new URL(args[1]);
0
Comment
Question by:dkim18
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Assisted Solution

by:shivsa
shivsa earned 100 total points
ID: 9894681
could u try to use escape before the special charactor.
0
 
LVL 4

Expert Comment

by:vk33
ID: 9894699
What platform are you running? For Win it works fine without escaping...
0
 
LVL 4

Assisted Solution

by:vk33
vk33 earned 25 total points
ID: 9894807
heh, I'm half asleep... What other platform could require *.bat files... :)
Really I don't know, I tried your code for one argument (arg[0]), it works allright without escaping '%' character. Maybe shivsa is right and you should escape it because your Windows parses it as a start of environment variable reference. But again on the WinXP of mine it worked alright.

Good luck!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Accepted Solution

by:
Breadstick earned 125 total points
ID: 9894847
In batch files, when you use a percent sign followed by a number, the percent and number are replaced with that argument that was passed to the batch file.  So if in a batch called hello.bat  I were to write:
echo %1
and then to execute it i typed:
hello.bat HelloWorld
then the program would echo HelloWorld

Your batch file is replacing %7 with the 7th argument that you passed the batch file.  Because you didn't pass it seven arguments, it's replacing it with nothing.
0
 
LVL 2

Expert Comment

by:Breadstick
ID: 9894867
To escape the percent in a batch file, you type %%.  Just the percent character twice.
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9894868
and thats why i said to escape since windows should not take it as a its own operator and treat it as a special character.
0
 
LVL 4

Expert Comment

by:vk33
ID: 9894883
Ah, yeah, well done Breadstick! I launched it directly from command line without batch-file...

Regards!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing to a specific printer tray (HP 806dn printer) 3 83
topping1 challenge 7 73
Java DateChooser? 3 29
Java Options in Zimbra Server 2 46
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now