简体   繁体   English

如何从Java执行外部程序?

[英]How do I execute an external program from Java?

Possible duplicates: 可能重复:


I want to execute a program of Perl from Java. 我想从Java执行Perl的程序。

I take a file name with an argument and carry out a program, and the program of Perl outputs a result file. 我使用带参数的文件名执行程序,Perl的程序输出结果文件。

So it is the program side of the JAVA 这就是JAVA的程序方面

  1. I appoint an argument and carry out Perl program 我指定一个参数并执行Perl程序
  2. Perl program reads the file which I spitted out Perl程序读取我吐出的文件

2) checks the existence of the file and seems to be able to do it, but will 1) be possible? 2)检查文件是否存在并且似乎能够执行此操作,但是1)可以吗? ActivePerl is installed with the present machine. ActivePerl已随本机一起安装。 I develop Java on Eclipse. 我在Eclipse上开发Java。

Use: 采用:

String command = "ls";    
Runtime.getRuntime().exec(command);

Reference: Executing a Command 参考: 执行命令

FYI: The link contains examples of commands with arguments, and with spaces too. 仅供参考:该链接包含带有参数和空格的命令示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM