使用java代码使用命令打开默认的linux终端 [英] open default linux terminal with command using java code

查看:508
本文介绍了使用java代码使用命令打开默认的linux终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用程序中使用命令打开Linux中的默认终端。

i使用java代码

这是我的代码但是不工作



 字符串 [] command = {   xterm  ls}; 
Runtime.getRuntime()。exec(command);





i得到此错误消息



 java.io.IOException:无法运行程序  xterm:error = 2,没有这样的文件或目录


在Linux Mint和Ubuntu上测试
i我得到了相同的结果

解决方案

看到这个......

如何创建一个打开终端窗口并在其中执行命令的脚本? - 询问Ubuntu [ ^ ]



要记住的一些事项:

0.当您运行终端时,它可能在完成工作后立即关闭。

1.您必须确保在env vars中有一条通往终端的路径。 />
2.有不同的终端仿真器,使用你系统安装的终端仿真器。



我现在正好在Windows 7机器上(我可以启动到Linux,但我正在备份我的磁盘)...这可以从cygwin终端工作(mintty是cygwin中的终端模拟器): mintty&

i need to open the default terminal in Linux from my app with command.
i use java code
this is my code but is not work

String[] command = { "xterm", "ls" };
Runtime.getRuntime().exec(command);



i get this error message

java.io.IOException: Cannot run program "xterm": error=2, No such file or directory


i tested on Linux Mint and Ubuntu i get the same result

解决方案

See this...
How can I make a script that opens terminal windows and executes commands in them? - Ask Ubuntu[^]

A few things to keep in mind:
0. When you run the terminal it might close right after finishing it's work.
1. You have to make sure you have a path to the terminal in your env vars.
2. There are different terminal emulators, use the one your system has installed.

I happen to be on a Windows 7 machine right now (I can boot to Linux but I'm in the middle of backing up my disks)... this works from a cygwin terminal (mintty is the terminal emulator in cygwin): mintty &


这篇关于使用java代码使用命令打开默认的linux终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆