• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass parameter from JSP to Batch file  RSS feed

 
Sudhakar Guntaka
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i had a small problem regarding passing parameter from JSP to a batch file.
My program is like this..........
I wrote a batch file which opens and pings a remote system. Code looks like this......
ping %1 -t
which takes one argument and named this as "a.bat"
The corresponding JSP page has lot of links which contains IP Addressess. From JSP page, i am calling "a.bat" so that it will open and start pinging corresponding IP Address. So i want to know how can i pass the corresponding IP from a JSP to batch file so that it start pinging remote machine........... can any body help me in this regard??
Thanks in Advance.

cheers,
Sudhakar.
 
Bajji Pat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sudhakar,

While calling the batch file itself pass the parameter to it like
a.bat XXXSYSTEM NAMEXXX
Does this solve your problem??
Balaji
 
Sudhakar Guntaka
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Balaji,
Thanks for your reply. I tried the way you told but it is not working.
My JSP or HTML page looks like this.....

HREF="c:\a.bat";

I am trying to call batch file with "HREF". I am not getting how to pass parameters to that batch file. can you suggest me some other way to sort out this problem.....
Thanks in advance.

cheers,
Sudhakar.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the version of Runtime.exec(String[] commandArray);
If you're going to start shelling out new processes from a JSP, you should do some reading first. You'll want to make sure you know how to stop them.
Ping on Windows runs 4 times and then stops. On most *nix systems, it runs until you stop it.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String[])
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

running a batchfile from a href works?

That must be Internet Explorer tzzz.

You could issue the command from your Java Code and read the result as a string.

See:

http://www.javaalmanac.com/egs/java.lang/Exec.html

http://www.javaalmanac.com/egs/java.lang/ReadFromCommand.html?l=rel

J.
 
Sudhakar Guntaka
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben and Jeffrey,
Thanks a lot for giving your valuable replies. I am able to solve the problem from your replies. Thanks once again...........

cheers,
Sudhakar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!