开发者

Call Cygwin from Java app

I need to call Cygwin from Java code ( example : to call make command in Cygwin from Java app which run on linux and windows ).Does anybody have e开发者_Go百科xperience with this problem ?


I think you have to differentiate youre code for linux and windows

  • on linux simply execute the command
  • on windows lauch your command in cygwin with

C:\cygwin\bin\bash.exe --login -i -c <cmd>

note: you may use apache commons exec to lauch an external command from java


Use ProcessBuilder from Java:

http://download.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html

You will need to make sure your path/environment is set up properly, but that depends on your machine and set up.

Also, note that many cygwin "capabilities" (e.g., less, awk, sed, etc) are simply binaries (executables) that you can call directly -- no need for the bash shell to facilitate access to those. Look at the actual files in wherever your bin folder is (usually c:/cygwin/bin) and try calling those directly from ProcessBuilder. If you need to actually leverage the shell (e.g., pipes, variables, globbing, etc) then that's a different story -- you would then integrate with the bash.exe file itself (check the man page for usage info).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜