如题,比如我想在java程序中调用
rsa_crypt.pl -[e|d] [“original string“| “encrypted string”]
,该怎么写啊,盼高手指点一二!

解决方案 »

  1.   

    String cmd = "rsa_crypt.pl -[e|d] [\"original string\"| '"encrypted string\"]";
    Process proc = Runtime.getRuntime().exec(cmd);
    try {
    proc.waitFor();
    } catch (InterruptedException e) {}
    int code = proc.exitValue();
      

  2.   

    The Runtime.exec methods may not work well for special processes on certain native platforms, 
     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里不能调用啊?
      

  3.   

    我现在的问题是,perl的结果不能实时返回,必须等perl程序执行完了之后才能返回所有的结果,这和预期不一样啊.大家知道怎么实时返回吗?急等....
      

  4.   

    学习了,回去试试Runtime.getRuntime().exec(cmd);以前一直想知道Java中怎么调用系统命令或C语言代码,难道就是这样调吗?
      

  5.   

    是这样调,但是我们用delphi写的可执行文件可以实时返回结果,而用perl写的程序效果就不好,返回的内容必须得够一定的字节才能够返回,并且感觉和在命令行执行速度上海市差许多.不知道为什么?
      

  6.   

    大家有人用过jsva调用userctl.pl命令往extmail中添加用户吗,我自己写了代码执行了 但是不会向extmail中插入数据.我的代码如下
    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;