从Java代码执行Shell脚本 [英] Executing Shell script from Java code

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

问题描述

我有gui,其按钮为安装到服务器" .... am具有ubuntu客户端和服务器系统.....当我单击安装按钮时,应将其安装到服务器文件夹... 例如,服务器中有一个文件夹名称"OUTPUT".在客户端计算机文件夹中是"OUTPUT FILES" ...通过linux命令,我可以从客户端文件夹"OUTPUT FILES"中安装服务器"OUTPUT"文件夹. 但是,在Java中,当我按下挂载按钮时,它应该挂载服务器的"OUTPUT"文件夹.我需要任何shellscript代码吗?...该怎么办? 以及如何获取服务器系统的IP地址?...请问有人可以帮助我吗?

I have the gui which have the button as "mount to server"....am having the ubuntu client and server system.....When I click the mount button ,it should mount to server folder... for example, one folder name "OUTPUT" is in the server..in client machine folder is "OUTPUT FILES"...through linux command i can mount the server "OUTPUT" folder from client folder "OUTPUT FILES".... But , in java when i press the mount button, it should mount the server "OUTPUT" folder..should i need any shellscript code?...how to do? and how to get the server system ip address?...can u plz anyone help me?

推荐答案

您可以编写一个Shell脚本以将服务器文件夹安装到客户端的文件系统上.一旦完成工作,就可以使用Runtime类从Java代码执行此Shell脚本.

You can write a shell script to mount the server folder onto your client's filesystem. Once you have that working, you can just execute this shell script from Java code using Runtime class.

    String IPAddress = "...";
    String script= "/path/to/your/script.sh";
    String[] cmd = {script, IPAddress};
    Runtime rt = Runtime.getRuntime();
    rt.exec(cmd);

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

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