2 sdyyy fan SDYYY_FAN 于 2016.03.23 16:51 提问

关于android 调用外部命令的问题(Runtime.getRuntime().exec参数)

android 调用外部命令的问题(Runtime.getRuntime().exec参数)
调用ls还有cat命名是没问题的,但是有些命令用不了,例如ll,打印显示环境有问题,不知道怎么解?

代码:
private String ssss() {
String TAG2 = "CMD";
try {

    String  cmd="ls";
    Process process =Runtime.getRuntime().exec(cmd);
    InputStream in1 = process.getInputStream();
    BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1));
    String line1;
    Log.i(TAG2, "返回结果" + reader1.readLine());
    while ((line1 = reader1.readLine()) != null) {

        Log.i(TAG2, "返回结果=" + line1);
    }
    in1.close();
} catch (IOException ex) {
    ex.printStackTrace();
    //  result2 = "N/A";
}
return null;

}

String cmd="ls"打印结果:
644-644/com.example.MEM I/CMD﹕ 返回结果acct
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=config
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=d
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=default.prop
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=etc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.goldfish.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.recovery.sun7i.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sdb.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sdd.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sun7i.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.trace.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=initlogo.rle
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=nand.ko
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=proc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=sbin
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=sun7i-ir.ko
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=system
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=ueventd.goldfish.rc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=ueventd.sun7i.rc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=null

String cmd="ll"打印结果:
03-23 16:46:52.337 3166-3166/com.example.MEM W/System.err﹕ java.io.IOException: Error running exec(). Command: [ll] Working Directory: null Environment: null
03-23 16:46:52.337 3166-3166/com.example.MEM W/System.err﹕ at java.lang.ProcessManager.exec(ProcessManager.java:211)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:168)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:241)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:184)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss(MyActivity.java:464)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)

3个回答

fengyun703
fengyun703   2016.03.24 08:40
已采纳

android 里面没有ll这个命令,用ls -l

fengyun703
fengyun703 回复SDYYY_FAN: 那可能是其他问题,反正我的没有ll命令。你可以echo $PATH,看看里面那些目录有ll吗。要是你shell能用ll,就应该有的。我这没有ll命令。
2 年多之前 回复
SDYYY_FAN
SDYYY_FAN ls -l 确实可以 但怎么看有没ll这个命令 ?在/system/bin下吗?里面是没有
2 年多之前 回复
SDYYY_FAN
SDYYY_FAN ls -l 确实可以 但怎么看有没ll折各命令 ?在/system/bin下吗?里面没有
2 年多之前 回复
SDYYY_FAN
SDYYY_FAN 我adb shell进去之后 ls 和ll都是可以的
2 年多之前 回复
lxk_1993
lxk_1993   Rxr 2016.03.23 18:22

和权限有关系吧 就像windows 需要管理员权限一样

SDYYY_FAN
SDYYY_FAN 可能吧 但是找不出问题,
2 年多之前 回复
SDYYY_FAN
SDYYY_FAN   2016.03.24 18:02

我装了一个ethtool工具(装在/system/bin下) $ethtool eth0 可以查看以太网信息

写了个apk,调用这个命令,然后返回打印信息

用2不同的Cubieboard开发板 一个能用 一个不能用,,,但是直接在板子上adb shell(执行ethtool eth0) 是可以用的

下面是打印信息:

ct:
com.example.MEM I/IR﹕ thread usb1 start
com.example.MEM I/IR﹕ thread usb1 start 500ms
com.example.MEM I/IR﹕ dd start
com.example.MEM W/System.err﹕ java.io.SyncFailedException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:77)
com.example.MEM W/System.err﹕ at java.io.FileOutputStream.flush(FileOutputStream.java:194)
com.example.MEM W/System.err﹕ at java.io.FilterOutputStream.flush(FilterOutputStream.java:88)
com.example.MEM W/System.err﹕ at java.io.DataOutputStream.flush(DataOutputStream.java:63)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss1(MyActivity.java:541)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)
com.example.MEM W/System.err﹕ at android.view.View.performClick(View.java:4206)
com.example.MEM W/System.err﹕ at android.view.View.onKeyUp(View.java:7792)
com.example.MEM W/System.err﹕ at android.widget.TextView.onKeyUp(TextView.java:5473)
com.example.MEM W/System.err﹕ at android.view.KeyEvent.dispatch(KeyEvent.java:2683)
com.example.MEM W/System.err﹕ at android.view.View.dispatchKeyEvent(View.java:7207)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1920)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1395)
com.example.MEM W/System.err﹕ at android.app.Activity.dispatchKeyEvent(Activity.java:2370)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1847)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3719)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3669)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2835)
com.example.MEM W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
com.example.MEM W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
com.example.MEM W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5041)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:582)
com.example.MEM W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
com.example.MEM W/System.err﹕ Caused by: libcore.io.ErrnoException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at libcore.io.Posix.fsync(Native Method)
com.example.MEM W/System.err﹕ at libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:97)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:74)
com.example.MEM W/System.err﹕ ... 30 more
com.example.MEM W/System.err﹕ java.io.SyncFailedException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:77)
com.example.MEM W/System.err﹕ at java.io.FileOutputStream.flush(FileOutputStream.java:194)
com.example.MEM W/System.err﹕ at java.io.FilterOutputStream.flush(FilterOutputStream.java:88)
com.example.MEM W/System.err﹕ at java.io.DataOutputStream.flush(DataOutputStream.java:63)
com.example.MEM W/System.err﹕ at java.io.FilterOutputStream.close(FilterOutputStream.java:61)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss1(MyActivity.java:542)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)
com.example.MEM W/System.err﹕ at android.view.View.performClick(View.java:4206)
com.example.MEM W/System.err﹕ at android.view.View.onKeyUp(View.java:7792)
com.example.MEM W/System.err﹕ at android.widget.TextView.onKeyUp(TextView.java:5473)
com.example.MEM W/System.err﹕ at android.view.KeyEvent.dispatch(KeyEvent.java:2683)
com.example.MEM W/System.err﹕ at android.view.View.dispatchKeyEvent(View.java:7207)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1920)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1395)
com.example.MEM W/System.err﹕ at android.app.Activity.dispatchKeyEvent(Activity.java:2370)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1847)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3719)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3669)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2835)
com.example.MEM W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
com.example.MEM W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
com.example.MEM W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5041)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:582)
com.example.MEM W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
com.example.MEM W/System.err﹕ Caused by: libcore.io.ErrnoException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at libcore.io.Posix.fsync(Native Method)
com.example.MEM W/System.err﹕ at libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:97)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:74)
com.example.MEM W/System.err﹕ ... 31 more
com.example.MEM I/IR﹕ ---------------------------Thread start

com.example.MEM I/IR﹕ ddddddddddddddddddddddddddddddddddddddddddddd= Settings for eth0:

com.example.MEM I/IR﹕ oooooooooooooooooo= Supported ports: [ TP AUI BNC MII FIBRE ]

com.example.MEM I/IR﹕ oooooooooooooooooo= Supported link modes: 10baseT/Half 10baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 100baseT/Half 100baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 1000baseT/Half 1000baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= Supported pause frame use: No

com.example.MEM I/IR﹕ oooooooooooooooooo= Supports auto-negotiation: Yes

com.example.MEM I/IR﹕ oooooooooooooooooo= Advertised link modes: 10baseT/Half 10baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 100baseT/Half 100baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 1000baseT/Half 1000baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= Advertised pause frame use: No

com.example.MEM I/IR﹕ oooooooooooooooooo= Advertised auto-negotiation: Yes

com.example.MEM I/IR﹕ oooooooooooooooooo= Speed: 1000Mb/s

com.example.MEM I/IR﹕ oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooookkkkkkkkkkkk1

com.example.MEM I/IR﹕ oooooooooooooooooo= Duplex: Full

com.example.MEM I/IR﹕ oooooooooooooooooo= Port: MII

com.example.MEM I/IR﹕ oooooooooooooooooo= PHYAD: 0

com.example.MEM I/IR﹕ oooooooooooooooooo= Transceiver: external

com.example.MEM I/IR﹕ oooooooooooooooooo= Auto-negotiation: on

com.example.MEM I/IR﹕ oooooooooooooooooo= Current message level: 0x0000003f (63)

com.example.MEM I/IR﹕ oooooooooooooooooo= drv probe link timer ifdown ifup

com.example.MEM I/IR﹕ oooooooooooooooooo= Link detected: yes

这个有报错 但是可以返回打印信息

ct plus:
com.example.MEM I/IR﹕ thread usb1 start
com.example.MEM I/IR﹕ thread usb1 start 500ms
com.example.MEM W/System.err﹕ java.io.IOException: write failed: EPIPE (Broken pipe)
com.example.MEM W/System.err﹕ at libcore.io.IoBridge.write(IoBridge.java:455)
com.example.MEM W/System.err﹕ at java.io.FileOutputStream.write(FileOutputStream.java:202)
com.example.MEM W/System.err﹕ at java.io.OutputStream.write(OutputStream.java:82)
com.example.MEM W/System.err﹕ at java.io.DataOutputStream.writeBytes(DataOutputStream.java:156)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss1(MyActivity.java:536)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)
com.example.MEM W/System.err﹕ at android.view.View.performClick(View.java:4438)
com.example.MEM W/System.err﹕ at android.view.View.onKeyUp(View.java:8241)
com.example.MEM W/System.err﹕ at android.widget.TextView.onKeyUp(TextView.java:5628)
com.example.MEM W/System.err﹕ at android.view.KeyEvent.dispatch(KeyEvent.java:2723)
com.example.MEM W/System.err﹕ at android.view.View.dispatchKeyEvent(View.java:7665)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2035)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1505)
com.example.MEM W/System.err﹕ at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3873)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3847)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3418)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3468)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3437)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3544)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3445)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3601)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3418)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3468)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3437)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3445)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3418)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3468)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3437)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3577)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3737)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2010)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1704)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1695)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1987)
com.example.MEM W/System.err﹕ at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
com.example.MEM W/System.err﹕ at android.os.MessageQueue.nativePollOnce(Native Method)
com.example.MEM W/System.err﹕ at android.os.MessageQueue.next(MessageQueue.java:138)
com.example.MEM W/System.err﹕ at android.os.Looper.loop(Looper.java:123)
com.example.MEM W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5017)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
com.example.MEM W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
com.example.MEM W/System.err﹕ Caused by: libcore.io.ErrnoException: write failed: EPIPE (Broken pipe)
com.example.MEM W/System.err﹕ at libcore.io.Posix.writeBytes(Native Method)
com.example.MEM W/System.err﹕ at libcore.io.Posix.write(Posix.java:202)
com.example.MEM W/System.err﹕ at libcore.io.BlockGuardOs.write(BlockGuardOs.java:197)
com.example.MEM W/System.err﹕ at libcore.io.IoBridge.write(IoBridge.java:450)
com.example.MEM W/System.err﹕ ... 50 more
这个报错,没有返回我要的打印信息

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Java调用批处理文件,Runtime.getRuntime().exec参数,示例
//测试结果:能打开,但是需要关闭文件才能中止程序。 //String[] cmd = {"notepad.exe","F:\\long_cennect.txt"}; //Process process = Runtime.getRuntime().exec(cmd); //测试结果:能打开文件,并且与程序独立,不关闭文件 程序也继续向下执行。 // /E:ON 允许cmd扩展 /c 指之后的
java 利用Runtime.getRuntime().exec()调用python脚本并传参
//TODO:执行python脚本 System.out.println("start python"); //需传入的参数 String a = "aaa", b = "bbb", c = "ccc", d = "ddd"; System.out.println("start;;;" + a);
Runtime.getRuntime().exec(...),参数带有空格的解决方法
今天在做用java自带的包来调用bat文件,当文件路径不带空格是执行正常,如下所示的情况是正常的: String command = "D:\\l\\phonemodel.bat";//exe,bat文件名OR DOS命令 Process proc = Runtime.getRuntime().exec(command); 这样执行可以给正常调用程序,不过在正式的环境中,路径带有空格,直接这
关于Runtime.getRuntime().exec("")的参数
下面这段代码copy的,原文也没有介绍,有兴趣的自己可以研究下 explore_folder_command=$exec("%SystemRoot%\explorer.exe" /n,/e,"%1") explore_folder_path_command=$exec("%SystemRoot%\explorer.exe" /n,/e,/select,"%1") open_folder_pa
Runtime.getRuntime().exec()实现Java调用python程序
Runtime.getRuntime().exec()实现Java调用python程序 在使用jython实现Java调用python程序,如果python程序中包含有第三方库(如numpy),则会报如下错误: Exception in thread "main" Traceback (innermost last): File "pyfile/detect.py", line 3,
MAC(苹果)-JAVA Runtime.exec调用 .app 程序
今天修改了一本MAC下用Runtime.exec调用.app的程序。因为需要在调用APP时自动打开文件。 以前的写法是Runtime.getRuntime().exec("open /user/test.app") 本想直接在后面加上空格及要打开的文件名,但是一直不成功。后来在苹果的终端下执行了命令 open -a /user/test.app  test.sml
java运行带参数的Runtime.getRuntime().exec()命令
package com.asterisk;import java.io.InputStreamReader;import java.io.LineNumberReader;public class RunAsterisk { /**  * @param args  */  public static void main(String[] args) {  // TODO Auto-ge
java Runtime.getRuntime().exec 调用系统脚本/命令注意事项
使用管道命令执行带密码执行sudo命令,在java中老是不成功今天找到方法解决了顺便整理了一下java Runtime.getRuntime().exec 调用脚本命令的注意事项。 使用管道命令执行带密码执行sudo命令 String cmds=“echo 'password' | sudo -S /usr/bin/pdf2htmlEX -h ”; 这个-S是读取前面的ech
Runtime.exec使用错误导致延迟
这篇文章是纪录了一个bug解决的过程,但是我还是没有能够真正地找出bug的缘由。希望大牛能够详细解释。问题的发现当接触的系统越来越大的时候,对于系统的性能越来越高的时候,找到表面问题的真正原因就慢慢地成为了一个比较麻烦的问题。说实话,一开始我一直不知道是因为Runtime.getRuntime().exec()导致服务处理时间缓慢。发现这个原因倒是花了不少时间。
Runtime.getRuntime().exec执行阻塞问题解决
上篇博文中CallMaxentThreadPoolTask类直接使用Runtime.getRuntime().exec方法调用cmd命令,结果今天在测试时发现当cmd命令执行 出现错误或警告时,主控程序的waitfor方法会被阻塞一直等待下去,查了查资料发现是Runtime.getRuntime().exec方法需要自己处理stderr 及stdout流,而解决方法即是将它们导出用别的thread处理。 会造成阻塞的代码: Process p = Runtime.getRuntime().exec