[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


run.bat file

Posted on 2003-12-07
Medium Priority
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 {

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

      System.out.println("args[1] " + args[1] );
      URL url = new URL(args[1]);
Question by:dkim18
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 24

Assisted Solution

shivsa earned 400 total points
ID: 9894681
could u try to use escape before the special charactor.

Expert Comment

ID: 9894699
What platform are you running? For Win it works fine without escaping...

Assisted Solution

vk33 earned 100 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!
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

Breadstick earned 500 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.

Expert Comment

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

Expert Comment

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.

Expert Comment

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


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

656 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