Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing a .bat file through jsp

 
Aakash Chandel
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"javafun jspfun" please check your private messages for an administrative matter.
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it is moved
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry to ask this but... Does Unix execute files with .bat extensions?
 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple answer: no

silly answer: you can execute a file with any extension on unix, if the executable flag is set.
 
Aakash Chandel
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that mean changing the extension from .bat to .sh will do the job?
 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no.
the content of a dos/windows batch file is not compatible with the content of a unix batch file.
 
Aakash Chandel
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1671
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic