Tag: runtime.exec

Java无法使用Runtime打开pdf

我必须在点击JMenuItem时打开一个pdf。 如果我从netbeans运行我的程序,我可以点击菜单项打开pdf。 但是当我从jar文件运行时它没有打开。 我清理并构建我的项目。 但没有变化。 从netbeans运行但不从jar文件运行时运行。 我需要添加一些库吗? 我的代码如下 m_aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Runtime rt = Runtime.getRuntime(); //System.out.println(Menubar1.getDefaultLocale()); URL link2=Menubar1.class.getResource(“/newpkg/Documentation.pdf”); String link=link2.toString(); link=link.substring(6); System.out.println(link); System.out.println(link2); String link3=”F:/new/build/classes/newpkg/Documentation.pdf”; try { Process proc = rt.exec(“rundll32.exe url.dll,FileProtocolHandler ” + link2); } catch (IOException ex) { Logger.getLogger(Menubar1.class.getName()).log(Level.SEVERE, null, ex); } } }); 试过这个但是得到了同样的东西..当我从netbeans运行而不是从jar应用程序运行时,我可以从menuitem打开pdf。 m_aboutItem.addActionListener(new ActionListener() { […]

在java程序中使用android aapt

我一直试图通过java程序执行aapt命令已有一段时间了。 我的预感是我应该使用runtime.exec()命令来实现这一点。 但是,我已经查看了其他问题和答案,似乎没有一个对我有用。 命令是: aapt package -u -f -F “/home/jay/testing_FILES.apk” “/home/jay/testing_FILES” 其中/home/jay/testing_FILES /home/jay/testing_FILES.apk是原始文件夹,而/home/jay/testing_FILES.apk是最终apk的打包名称和位置。 任何人都可以向我解释如何使用aapt和java runtime.exec()正确运行此命令?

使用java恢复PostgreSQL数据库

我使用以下代码使用java恢复PostgreSQL数据库 Runtime r = Runtime.getRuntime(); Process p; String cmd =”D:/Program Files/PostgreSQL/9.1/bin/pg_restore.exe –host localhost –port 5432 –username postgres –dbname mytestqq –role postgres –no-password –verbose D:\sathish\rawDatabase.backup”; p = r.exec(cmd); 我在rawDatabase.backup文件中有42个表,但只有一个表正在恢复为什么其余的表没有发生我的代码中的错误? 提前致谢!!!!

从Java代码中运行程序

使用一段Java代码调用程序的最简单方法是什么? (我想运行的程序是aiSee,它可以从命令行或Windows GUI运行;我在Vista上,但代码也将在Linux系统上运行)。

如何通过Java swing执行cmd命令

我有一个要打印的文件,我想通过java swing向他发送自定义水印。 我有2个文件NewJFrame.java和Test.java package test; import java.io.IOException; import java.io.OutputStream; /** * * @author shaharnakash */ public class NewJFrame extends javax.swing.JFrame { /** * Creates new form NewJFrame */ public NewJFrame() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The […]

Runtime.getRuntime()。exec()执行两行?

我需要在Runtime.getRuntime()。exec()中运行两行,这两行: cd %CMS_HOME% ant deploy 现在可以制作一个.bat文件,但我觉得它对于两行是没用的,更简单! 有人有什么想法吗?

带有参数的Java Runtime Exec for VBA脚本

我试图使用Runtime exec()来运行带有争论的vba脚本。 我在传递args时遇到了麻烦。 我想我需要为exec使用String []重载方法。 目前这工作: String command = “cmd /c \”\\concat2.vbs\”” Process p = Runtime.getRuntime().exec(command); 但我想用争论来运行它,如果我这样做的话 String command = “cmd /c \”\\concat2.vbs\” ” + arg1 + ” ” + arg2 其中arg1和arg2是我的程序不运行的字符串(status = 1)

杀死Java中调用的子进程的问题

在我的程序中,我调用一个Linux进程,从该进程读取输出,处理它然后睡眠直到下一次迭代。 我遇到的问题是我调用的进程并不总是死,即使我做了childProcess.destroy() 。 这是代码: while(true) { Process childProcess = Runtime.getRuntime().exec(“./getData”); InputStream input = childProcess.getInputStream(); BufferedReader inPipe = new BufferedReader(new InputStreamReader(input)); while((lineRead = inPipe.readLine()) != null) { // do stuff } childProcess.destroy(); inPipe.close(); input.close(); } 绝大多数时候,。/ getData运行,优雅地退出,我的程序按原样运行。 但….有时它不会退出,只是坐在那里消耗CPU。 我需要一种杀掉它的方法。 我也尝试在调用它之前添加它,但这不起作用: Process killGetData = Runtime.getRuntime().exec(“pkill -9 getData”); killGetData.destroy(); 我猜也许我会陷入内在的while()循环中。 感激地收到任何想法,想法和小贴士。 提前谢谢了 约翰

Runtime.getRuntime()。exec(),执行Java类

我正在从我的应用程序中执行Java类。 proc = Runtime.getRuntime().exec(“java Test”); 如何识别Test是否成功执行(即没有例外)? 重定向输出/错误: proc = Runtime.getRuntime().exec(new String[] { “java”, mclass, “>NUL 2>test.txt” }); 从cmd : java Main >NUL 2>test.txt

java中操作系统的名称(不是“os.name”)

我想知道如何掌握jvm运行的那种操作系统。 它也必须是“安全的”,因此System.getProperty(“os.name”)实际上不是一个选项,因为它可以通过-D指令轻易绕过。 通过“安全”,我的意思是不容置疑。 它适用于桌面应用程序。 用户总是可以对代码进行反混淆,反编译,编辑和重新编译,但这比将-D传递给jvm要困难得多。 我们想要修补不平凡,而不是不可能(因为那是不可能做到的)。