如题,比如我想在java程序中调用
rsa_crypt.pl -[e|d] [“original string“| “encrypted string”]
,该怎么写啊,盼高手指点一二!
rsa_crypt.pl -[e|d] [“original string“| “encrypted string”]
,该怎么写啊,盼高手指点一二!
解决方案 »
- Collection与iterator()的关系
- stringBuffer为什么没有trim方法
- 难道 java 真的连这个都不能实现吗????
- 怎么解读这个程序(编译顺序)
- 有没有做snmp网管软件的?探讨下这个职业的前途问题
- 为什么每次写入都会在前面的内容后呢?
- jdbc 纯JAVA代码数据库连接...
- 请文如何用java创建不规则窗口?
- ResultSet中的数据转到javabean的array
- 如何把457.20$转换为FOUR HUNDRED FIFTY SEVEN DOLLARS AND CENTS TWENTY
- 100分求 DJ Java Decompiler v.3.9.9.91注册码
- jfreeChart时序图横轴标尺值只显示奇数天,不能显示一个月的所有天数?
Process proc = Runtime.getRuntime().exec(cmd);
try {
proc.waitFor();
} catch (InterruptedException e) {}
int code = proc.exitValue();
such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft
Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its
standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through
three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()).
The parent process uses these streams to feed input to and get output from the subprocess.
Because some native platforms only provide limited buffer size for standard input and output
streams, failure to promptly write the input stream or read the output stream of the subprocess
may cause the subprocess to block, and even deadlock. 然后我测试了下,
结果出现错误
java.io.IOException: CreateProcess: /rsa_crypt.pl -d '326234072' error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)是不是说在windows里不能调用啊?
String comm = "perl /var/www/extsuite/extman/tools/userctl.pl--mod=add -username="+uname +"-password="+pass;
runLinuxCmd(String cmd) //本类调用public String runLinuxCmd(String cmd) {
BufferedReader bf = null;
try {
Process process = Runtime.getRuntime().exec(cmd);
bf = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
String resutl="";
while ((line = bf.readLine()) != null) {
resutl =resutl+ line.trim()+"\n";
}
System.out.println("---------------try result------------------"+resutl);
return resutl;
} catch (java.io.IOException e) {
e.printStackTrace();
System.out.println("------------error--------------");
return null;
} finally {
if (bf != null) {
try {
bf.close();
bf = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} }
单独在shell环境下执行perl命令是没有问题,能够插入数据,但是java调用能够执行不报错, 但是没有返回值,我在网上看到有朋友说过要把perl的命令写进shell脚本去 , 再用java调用 shell命令 , 我还没有学过lniux不知道怎么写 , 写这个脚本的时候需要接收外部传过来的username 和 password参数给perl命令 ,那个哥哥姐姐做过 能跟我讲一下么 如果可以的话能发到我邮箱吗[email protected] 感激不尽如果我上面没有表述明白 下面 简单的表述一下的我问题: 我想在java中调用perl命令向数据库里面插入数据。 perl命令是: perl /var/www/extsuite/extman/tools/userctl.pl--mod=add -username="+uname +"-password="+pass;