Re: unix环境下如何在java程序中执行命令行?# Java - 爪哇娇娃
p*a
1 楼
Runtime.exec() returns a Process which has an input
stream and an output stream. You should read from
the Process's output (called getInputStream though)
and dump it to the screen. Windows' implementation
doesn't follow the spec (did you use Microsoft's
VJ++? :))
The following code works:
import java.io.*;
public class tstr
{
public static void main(String args[])
{
Runtime r = Runtime.getRuntime();
Process theProcess = null;
try {
theProcess = r.exec("ls -l");
stream and an output stream. You should read from
the Process's output (called getInputStream though)
and dump it to the screen. Windows' implementation
doesn't follow the spec (did you use Microsoft's
VJ++? :))
The following code works:
import java.io.*;
public class tstr
{
public static void main(String args[])
{
Runtime r = Runtime.getRuntime();
Process theProcess = null;
try {
theProcess = r.exec("ls -l");