java调用shell返回值问题 shell中调用另一程序有返回值,此时java调用此shell无法获得程序的返回值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没写过shell,不过shell也能想方法一样返回值吗,你可以贴出一个程序研究一下 直接终端中调用此shell 可以输出结果,使用java调用此shell无法获得输出值shell脚本部分代码#!/bin/shdsVal=`/info/IBM/InformationServer/Server/DSEngine/bin/dsjob -user xx -password xx -server TESTDS:31539 -jobinfo dstage1 SQ_CWWJ__T_CWWJ_GLFY_SY`echo dsValexit 0 java里需要从流里去读取shell的输出,并不是shell可以直接返回 InputStream is = process.getInputStream ( ) ; byte[] buffer = new byte[1024] ; while ( is.read(buffer) != -1 ) { result = new String (buffer) ; } is.close ( ) ; 是从流中读取的,就是的不到输出值啊 #!/bin/sh dsVal=`/info/IBM/InformationServer/Server/DSEngine/bin/dsjob -user xx -password xx -server TESTDS:31539 -jobinfo dstage1 SQ_CWWJ__T_CWWJ_GLFY_SY` echo $dsValecho "hello world!" exit 0 可以从流中换取到“hello world” 但是得不到dsVal的变量的值 Process pid = null; pid = Runtime.getRuntime().exec(shellCommand); 的确采用Runtime,Process。问题是inputStream获得不了值?直接运行shell文件终端可看到,而用java调用则无法获得继续up! 我遇到的问题 与此贴类似 http://bbs.csdn.net/topics/280053880 烦请知道的朋友指点下thanks! String[] cmds = {"/bin/sh", "-c" , "sssss.sh"}; 组合框怎么变成一条直线了啊!! 请f教SWT中 CTabFolder问题 有关Java操作word的问题(jacob) 一个生产者消费者线程关闭的问题 关于反射的一个问题。 JTable的右键事件如何实现 请教大哥一个弱智问题,用jsp做客户端,servlet做服务器端 一段字符串,求其中单词的个数。求大神 哪里有Thinking in Java第二版的课后题答案(部分也行)下载?(高分相赠) JAVA编译问题 一个关于Client端和Server端的问题 还是会出现异常,帮忙解决异常
shell脚本部分代码#!/bin/shdsVal=`/info/IBM/InformationServer/Server/DSEngine/bin/dsjob -user xx -password xx
-server TESTDS:31539 -jobinfo dstage1 SQ_CWWJ__T_CWWJ_GLFY_SY`echo dsValexit 0
byte[] buffer = new byte[1024] ;
while ( is.read(buffer) != -1 ) {
result = new String (buffer) ;
}
is.close ( ) ;
#!/bin/sh
dsVal=`/info/IBM/InformationServer/Server/DSEngine/bin/dsjob -user xx -password xx
-server TESTDS:31539 -jobinfo dstage1 SQ_CWWJ__T_CWWJ_GLFY_SY`
echo $dsValecho "hello world!"
exit 0
可以从流中换取到“hello world” 但是得不到dsVal的变量的值
pid = Runtime.getRuntime().exec(shellCommand);
烦请知道的朋友指点下thanks!