Tag: exec

我如何从Java程序启动完全独立的进程?

我正在使用Java编写的程序, 对于某些操作 ,使用用户configuration的命令行启动外部程序。 目前它使用Runtime.exec()并不保留Process引用(启动的程序是文本编辑器或归档实用程序,因此不需要系统input/输出/ errstream)。 这个问题有一个小问题,那就是当Java程序退出的时候,直到所有已经启动的程序退出,它才真正退出。 如果启动的程序完全独立于启动它们的JVM,我会更喜欢它。 目标操作系统是多个,Windows,Linux和Mac是最小的,但任何带有JVM的GUI系统都是真正需要的(因此实际命令行的用户可configuration性)。 有谁知道如何使启动的程序完全独立于JVM执行? 编辑回应评论 启动代码如下。 代码可以启动位于特定行和列的编辑器,也可以启动存档查看器。 在configuration的命令行中引用的值被视为ECMA-262编码,并被解码,引号被剥离以形成所需的exec参数。 发射发生在美国东部时间。 static Throwable launch(String cmd, File fil, int lin, int col) throws Throwable { String frs[][]={ { "$FILE$" ,fil.getAbsolutePath().replace('\\','/') }, { "$LINE$" ,(lin>0 ? Integer.toString(lin) : "") }, { "$COLUMN$",(col>0 ? Integer.toString(col) : "") }, }; String[] arr; // array of parsed […]

如何用参数执行命令?

如何使用参数在Java中执行命令? Process p = Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php -m 2"}); 没有工作。 String[] options = new String[]{"option1", "option2"}; Runtime.getRuntime().exec("command", options); 也没有工作,因为它没有指定“m”参数。

Python 2和Python 3中的exec函数的行为

以下代码在Python2和Python3给出了不同的输出: from sys import version print(version) def execute(a, st): b = 42 exec("b = {}\nprint('b:', b)".format(st)) print(b) a = 1. execute(a, "1.E6*a") Python2打印: 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] ('b:', 1000000.0) 1000000.0 Python3打印: 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] b: 1000000.0 42 为什么Python2将execute函数中的variablesb绑定到exec函数string中的值,而Python3不这样做? 我如何在Python3实现Python2的行为? 我已经尝试将globals和locals的字典传递给Python3 […]

从另一个Python脚本调用Python脚本的最好方法是什么?

我有一个名为test1.py的脚本,它不在模块中。 它只有脚本本身运行时应该执行的代码。 没有函数,类,方法等我有另一个脚本作为服务运行。 我想从作为服务运行的脚本调用test1.py。 例如: 文件test1.py print "I am a test" print "see! I do nothing productive." 文件service.py # Lots of stuff here test1.py # do whatever is in test1.py 我知道有一种方法是打开文件,阅读内容,并基本评估它。 我假设有一个更好的方法来做到这一点。 或者至less我希望如此。

fork和exec之间的区别

fork和exec什么区别?

如何在Python中执行包含Python代码的string?

如何在Python中执行包含Python代码的string?

如何使pipe道与Runtime.exec()?

考虑下面的代码: String commandf = "ls /etc | grep release"; try { // Execute the command and wait for it to complete Process child = Runtime.getRuntime().exec(commandf); child.waitFor(); // Print the first 16 bytes of its output InputStream i = child.getInputStream(); byte[] b = new byte[16]; i.read(b, 0, b.length); System.out.println(new String(b)); } catch (IOException e) { e.printStackTrace(); […]