`

JAVA在linux上以管理员身份执行Command

阅读更多
try {
	Process process = Runtime.getRuntime().exec("su");  //以管理员身份运行
	DataOutputStream os = new DataOutputStream(process.getOutputStream()); 
	os.writeBytes("tar -jxvf /home/kylin/license/test.cpk -C ./test2\n");  //执行命令1:将test.cpk文件解压到当前目录的test2文件夹下
	os.writeBytes("exit\n");  //执行命令2:退出操作 
	os.flush();
	process.waitFor();  //这一步很重要:直至解压缩操作执行完成后,才执行下面的操作。否则,没有添加此句的话,在后续操作中如果要引用解压后的文件,就会由于未解压完成而找不到文件报错。

	//后续操作
	checkLicenseContent(resBean, licenseFileContent, false, null);
} catch (Exception e) {
	e.printStackTrace();
}
分享到:
评论

相关推荐

    the linux command line

    You've experienced the shiny, point-and-click surface of your Linux computer-now dive below and explore its depths with the power of the command line. The Linux Command Line takes you from your very ...

    Java调用Linux命令

    Java调用Linux命令 调用Runtime.exec方法将产生一个本地的进程,并返回一个Process子类的实例, (注意:Runtime.getRuntime().exec(command)返回的是一个Process类的实例), 该实例可用于控制进程或取得进程的...

    Linux Command Background

    Linux Command Background Linux Command Background Linux Command Background

    java调用shell脚本执行sqlldr与存储过程

    /home/oracle/.bash_profile 这句话,否则在执行sqlldr会报如下异常: Message 2100 not found; No message file for product=RDBMS...... facility=UL 【采用此法测试以后继续报错,但是这个方法有引导作用,继续...

    Linux command introduction.

    command line to tell a Linux system what to do. Here’s an example command that counts lines of text in a file, myfle: wc -l myfile We’ll cover the most important Linux commands for the aver‐ age ...

    Command-linux命令

    Command-linux命令

    OS + linux command / Linux Command / Linux command / linux Command

    NULL 博文链接:https://lindows.iteye.com/blog/223297

    Beginning the Linux Command Line

    All Linux users and administrators tend to like the flexibility and speed of Linux administration from the command line in byte–sized chunks, instead of fairly standard graphical user interfaces....

    The Linux Command Line.pdf

    The Linux Command Line; 2019/1/28; 19.01; This book is part of the LinuxCommand.org project

    the simple command of linux

    the simple command of linux

    Complete Linux Command Reference

    Complete Linux Command Reference

    linux command (全)

    linux command (全) 介绍各种linux指令代码,相当的全。

    The Linux Command Line

    You've experienced the shiny, point-and-click surface of your Linux computer-now dive below and explore its depths with the power of the command line. The Linux Command Line takes you from your very ...

    linux command line.pdf

    linux command line.pdf 介绍关于linux命令行的知识。

    The Linux Command Line 中文版

    本书是The Linux Command Line 的中文版,帮助新手入门和老鸟进阶,可以中英文对照着读,效果更佳(小小搬运工,省的大家去找,不喜勿喷)

    Linux_command_tutorial

    Linux command tutorial It's easy

    Linux Command Line

    This book is part of the LinuxCommand.org project, a site for Linux education and advocacy devoted to helping users of legacy operating systems migrate into the future. You may contact the Linux...

    Linux.Command(PDF)

    Linux.Command,Linux下命令详解。

    Linux_Command_Line

    这是一本讲linux command line的书

Global site tag (gtag.js) - Google Analytics