如何运行从Java脚本的cygwin [英] how to run cygwin script from java

查看:124
本文介绍了如何运行从Java脚本的cygwin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行Java程序我在windows写一个bash脚本。我一直在试图使用Runtime对象来获取一个过程来工作,我的程序编译,并没有异常运行,但我简单的测试脚本,它只是使一个目录,没有被执行。

I'm trying to run a bash script from a Java program I'm writing in windows. I've been trying to use the Runtime object to get a process to work, and my program compiles and runs without exceptions, but my simple test script, which just makes a directory, is not being executed.

下面就是我这么远:

String cmmd[] = new String[3];
    cmmd[0] = "C:\\cygwin\\bin\\bash.exe";
    cmmd[1] = "cd C:/Users/pro-services/Desktop/projects/github/cygwin";
    cmmd[2] = "bash TEST.sh";

    Runtime rt= Runtime.getRuntime();
    Process proc = rt.exec(cmmd);

这基本上是不同的东西,我在各地的网论坛发现了一个组合,但我想我只是真的不明白什么是与Process类发生的事情(我只对运行时类基本思路)。

This is basically a mix of different things I've found in forums around the net, but I guess I just don't really understand what is happening with the Process class (and I only have a basic idea about the Runtime class).

我也发现了这一点,并插入我自己的东西在我认为它应该:

I also found this, and plugged my own stuff in where I thought it should go:

Runtime.getRuntime().exec(new String[]{"C:\\cygwin\\bin\\bash.exe",
                                                    "-c", "c:\\cygwin\\bin\\run.exe -p /bin bash C:\\Users\\pro-services\\Desktop\\projects\\github\\cygwin\\TEST.sh"},
                                      new String[]{"PATH=/cygdrive/c/cygwin/bin"});

在这里我不知道是什么 - C - P字符串重新present,但我只是去用它。起初,它看起来像我可能只需要插上我想要的运行时间/ Process对象执行顺序的命令,在本质上创建一个剧本来运行我的脚本。但现在看来,还有更多的是...

Here I'm not sure what the "-c" and "-p" strings represent, but I just went with it. At first it looked like I could just plug in the sequential commands that I want the Runtime/Process object to execute, in essence creating a "script" to run my script. But it now seems that there's more to it...

我只是在黑暗中拍摄在这一点上,我试图理解文档,但我迷路了。任何帮助将是AP preciated。谢谢)))

I'm just shooting in the dark at this point, and I have tried to understand the documentation but I'm lost. Any help would be appreciated. Thanks )))

推荐答案

未经检验的,但我认为:

Untested, but I would think:

cmmd[0] = "C:/cygwin/bin/bash.exe";
cmmd[1] = "-c";
cmmd[2] = "cd /cygdrive/c/Users/pro-services/Desktop/projects/github/cygwin && bash TEST.sh";

这篇关于如何运行从Java脚本的cygwin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆