3

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.

sed -i "s/<model.version>2.1.1-SNAPSHOT<\/model.version>/<model.version>2.1.1-b-1<\/model.version>/g" pom.xml 

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.

Following is the piece of code that works fine. The only problem is that it invokes command prompt. I want to invoke cygwin shell instead of command prompt.

File dir = new File("C:\\Projects\\release-builds"); Runtime.getRuntime().exec("cmd.exe /c start build-model.bat", null, dir); 

Please advise.

2
  • 4
    Is this really the best way to do what you want? It seems like a lot of overhead. Can't you do what you want in java? Commented Dec 16, 2010 at 18:27
  • 1
    Down this path lies pain. And madness. But mostly pain, I guess. Commented Dec 17, 2010 at 0:06

2 Answers 2

2

You need to add the cygwin directory to your PATH. (or the PATH of your service) then you can run cygwin commands from a DOS prompt or bat script.

Or you can give the full path for your c:\cygwin\usr\bin\sed.exe or whatever it is.

Sign up to request clarification or add additional context in comments.

2 Comments

You can minimise the window automatically, I assume you don't want to see the window at all? You cannot run a batch script from cygwin. Only sh/bash shell scripts. To run a bash script, run bash.exe -c instead of cmd.exe
well, i ran the batch file into cygwin shell on Windows and it worked perfectly fine for me. i went into the bash shell by using command bash --login -i through the windows run dialog box and then executed my batch file using ./build-model.bat and it went fine.
2

Is just getting sed from gnuwin project an option? You could use it with native windows shell then.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.