aspose file tools*
The moose likes General Computing and the fly likes Executing a .bat file through jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Executing a .bat file through jsp" Watch "Executing a .bat file through jsp" New topic
Author

Executing a .bat file through jsp

Aakash Chandel
Greenhorn

Joined: Aug 31, 2010
Posts: 27
I am trying to execute a BATCH file through through a jsp on a Windows machine and it works fine without any problems.

However DOS does not have an equivalent of sed unix command. Hence I had to install cygwin so that I can use the the following sed command in my batch file.


My question is that how can I invoke the cygwin shell so that my .bat file runs within cygwin shell rather than windows command prompt.



Please advise.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

"javafun jspfun" please check your private messages for an administrative matter.


OCUP UML fundamental and ITIL foundation
youtube channel
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

And please try to post in the correct forum. "How do I run the Cygwin shell" is not a question about JSP, so let's move the question elsewhere.
Aakash Chandel
Greenhorn

Joined: Aug 31, 2010
Posts: 27
I wasn't sure what forum to pick hence I posted it in jsp forum. Please let me know if it's been moved to some other forum
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

yes, it is moved
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

I'm sorry to ask this but... Does Unix execute files with .bat extensions?


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

simple answer: no

silly answer: you can execute a file with any extension on unix, if the executable flag is set.
Aakash Chandel
Greenhorn

Joined: Aug 31, 2010
Posts: 27
Does that mean changing the extension from .bat to .sh will do the job?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

no.
the content of a dos/windows batch file is not compatible with the content of a unix batch file.
Aakash Chandel
Greenhorn

Joined: Aug 31, 2010
Posts: 27
I tried following steps based on the feedback from the forum:

1) Added Cygwin\bin into my Windows PATH
2) Modified the .bat extension to .sh and also made the file unix compatible and ran it on cygwin shell just to make sure that it works using the following command:

It worked without any problems.

3) Now it was time to run the same .sh file through my JSP:

4) I got the following output messages on console without any error messages but the shell script didn't work.


I have the following piece of code in my shell script: -- build-model.sh --


What I am not able to understand is that the same shell script runs perfectly fine when ran directly on the cygwin bash shell. But when I run the same shell script through JSP it fails silently without any error messages.

Please advise.




Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
If you insist on doing this via shell script/batch file, then I would recommend you go check outthis article. It documents the pitfalls on using Runtime.exec.

Personally, I question the whole thing.

Why do you want to execute a batch file? To do an svn checkout, run sed to do some replacements within the file...
ever heard of a program called Ant? I reckon you might find it useful in this case. And its java based, so you don't even need to bother with runtime.exec.

So yeah. I would recommend you step back, take a look at what you are trying to accomplish, and re-evaluate if you are doing the correct things. When you start getting into batch files and runtime.exec, I think you're on the wrong path.

Aakash Chandel
Greenhorn

Joined: Aug 31, 2010
Posts: 27
The whole idea behind using Runtime exec() method was to execute the batch file through Outlook Express.

As a part of normal procedure, we usually cut the tag release from the trunk couple of times in a month and we do it manually all the time. This is time taking and requires manual intervention.

Hence in order to automate the tag release the idea was to prepare a batch file which contains all the svn checkout commands, sed command to modify the pom, do an svn commit after modifying pom and then release the tag. Since Outlook Express does not execute batch files directly, the only way was to create a web application and the jsp file would call this batch file using Runtime.exec() and then make Outlook Express launch the application. This way we can launch the application and do a tag release by sending just one email.

I hope I was able to make you understand what I am trying to achieve. Please feel free to give your suggestions.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Outlook Express? Isn't that an e-mail client? Wouldn't have been in my top ten choices to do application deployment. Or am I misunderstanding something?
Aakash Chandel
Greenhorn

Joined: Aug 31, 2010
Posts: 27
Yes, you are right. Outlook Express (OE) is an email client and it has a feature that can be used to launch an application. One can define rules in OE and based on those rules we can launch an EXE or open a browser etc. In my case, I am trying to launch a browser and hit a url. I am trying to automate a manual task just by sending an email to myself and then the rules defined in OE would launch my web application and do a tag release.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing a .bat file through jsp