开发者

How can I pass a parameter from a Java application to a Cygwin command?

Currently I am doing a project in which I need to pass the parameter from the Java application (basically Java Swing) into the Cygwin command interface. How can I do this?

Th开发者_开发知识库anks


If you look at the contents of Cygwin.bat, you'll see it calls the bash.exe binary:

@echo off

C:
chdir C:\cygwin\bin

bash --login -i

Command binaries usually have a help argument. In this case, bash most certainly does:

bash --help
GNU bash, version 3.2.49(23)-release-(i686-pc-cygwin)
Usage:  bash [GNU long option] [option] ...
        bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option
Type `bash -c "help set"' for more information about shell options.
Type `bash -c help' for more information about shell builtin commands.
Use the `bashbug' command to report bugs.

Now that we know what options it takes, your Java application can call bash directly:

String commandString = "help";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\\cygwin\\bin\\bash -c " + commandString);

Remember to replace commandString with the value from your Swing component.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜