从Java执行屏幕命令 [英] Executing screen command from Java

查看:75
本文介绍了从Java执行屏幕命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在Linux中执行SH文件

I am using the following code to execute an SH file in Linux

Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", file.getPath() });

此代码有效,但是从Java执行该命令时,我无法在SH文件中使用screen命令,但出现此错误

This code works however I can't use the screen command in the SH file when executing it from Java, I get this error

必须连接到终端.

Must be connected to a terminal.

那么可以将Java连接"到终端吗?当我通过SSH连接时,我还希望能够查看此屏幕,因此我认为它必须连接到通过SSH进入服务器时显示的终端.

So is it possible to "connect" java to a terminal? I would like to be able to also view this screen when I connect via SSH so I think it has to be connected to the terminal that is shown when you SSH into the server.

推荐答案

我发现,如果使用screen -dm,它将起作用.谢谢!

I found that if I use screen -dm it will work. Thanks!

这篇关于从Java执行屏幕命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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