如何在java中使用Cygwin运行shell脚本 [英] how to run shell script in java using Cygwin

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

问题描述

从很久以来,我一直在努力与这个程序。我有一个shell脚本接受参数作为版本号和文件的路径。

From a long time i am struggling for with this program. I am having a shell script which accepts parameters as version number and path for the files. then that script creates Zip file with the name of version number congaing all file files to the folder.

我已经安装Cygwin到以下路径 D:/ cygwin

I have installed Cygwin on following path D:/cygwin. I am coping required files to same location where cygwin is installed D:\cygwin\bin

命令

D:/ cygwin / bin / bash -c'/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files

D:/cygwin/bin/bash -c '/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files

或者任何人都可以建议如何使用Cygwin在java中运行shell脚本

Or Can any one please suggest how to run shell script in java using Cygwin.

重写问题: -

当我试图在命令提示符下运行以下命令时会出现错误

When i am trying to run following Command in command prompt it gives error

sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files

错误:-C:\Documents和Settings \\ \\sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files

Error:-C:\Documents and Settings\sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files

/usr/bin/app.sh:第51行:lib / lib .sh:没有这样的文件或目录

/usr/bin/app.sh: line 51: lib/lib.sh: No such file or directory

但是如果我在

D:cygwin\\ \\ bin \Test> sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files

D:cygwin\bin\Test>sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files

它可以正常工作。任何一个建议我如何避免这种错误。

It works fine. Can any one suggest me how to avoid this kind of errors.

推荐答案

Runtime run = Runtime.getRuntime();
Process p = run.exec("D:/cygwin/bin/bash -c \'/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files");
p.waitFor();

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

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