<i id='4oiXx'><tr id='4oiXx'><dt id='4oiXx'><q id='4oiXx'><span id='4oiXx'><b id='4oiXx'><form id='4oiXx'><ins id='4oiXx'></ins><ul id='4oiXx'></ul><sub id='4oiXx'></sub></form><legend id='4oiXx'></legend><bdo id='4oiXx'><pre id='4oiXx'><center id='4oiXx'></center></pre></bdo></b><th id='4oiXx'></th></span></q></dt></tr></i><div id='4oiXx'><tfoot id='4oiXx'></tfoot><dl id='4oiXx'><fieldset id='4oiXx'></fieldset></dl></div>

  • <tfoot id='4oiXx'></tfoot>

        <bdo id='4oiXx'></bdo><ul id='4oiXx'></ul>

      <small id='4oiXx'></small><noframes id='4oiXx'>

        <legend id='4oiXx'><style id='4oiXx'><dir id='4oiXx'><q id='4oiXx'></q></dir></style></legend>

        实施“系统"Java中的命令

        Implementing the quot;systemquot; command in Java(实施“系统Java中的命令)
          <legend id='XQiKT'><style id='XQiKT'><dir id='XQiKT'><q id='XQiKT'></q></dir></style></legend>
        • <tfoot id='XQiKT'></tfoot>

              <small id='XQiKT'></small><noframes id='XQiKT'>

                <bdo id='XQiKT'></bdo><ul id='XQiKT'></ul>

                    <tbody id='XQiKT'></tbody>

                  <i id='XQiKT'><tr id='XQiKT'><dt id='XQiKT'><q id='XQiKT'><span id='XQiKT'><b id='XQiKT'><form id='XQiKT'><ins id='XQiKT'></ins><ul id='XQiKT'></ul><sub id='XQiKT'></sub></form><legend id='XQiKT'></legend><bdo id='XQiKT'><pre id='XQiKT'><center id='XQiKT'></center></pre></bdo></b><th id='XQiKT'></th></span></q></dt></tr></i><div id='XQiKT'><tfoot id='XQiKT'></tfoot><dl id='XQiKT'><fieldset id='XQiKT'></fieldset></dl></div>
                  本文介绍了实施“系统"Java中的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要一个系统"函数调用,与 Python、Perl、PHP、Ruby 和 &c 中的函数调用相同.当它在 Rhino JavaScript 引擎上运行时,它将成为一个名为 Narwhal 的 JavaScript 标准库的组件,而 Rhino JavaScript 引擎又在 Java 上运行.

                  I have need for a "system" function call, the same as those in Python, Perl, PHP, Ruby, &c. It will be a component of a JavaScript standard library called Narwhal, when it's run on the Rhino JavaScript engine, which is in turn run on Java.

                  问题在于,Java 的标准库似乎已经抽象出生成子进程的能力,该子进程共享父进程的标准输入输出.这意味着您不能将交互性推迟到子流程.

                  The trouble is that Java's standard library appears to have abstracted away the ability to spawn a subprocess that shares the parent process's stdio. This means that you can't defer interactivity to the subprocess.

                  我的第一次尝试是实现 Python 的 subprocess.popen.这使用三个泵"线程来主动独立地复制父进程的标准输入输出(以防止死锁).不幸的是,这给我们带来了两个问题.首先,当子进程自愿退出时,输入不会自动关闭.其次,子进程的流没有正确缓冲和刷新.

                  My first crack at this was to implement Python's subprocess.popen. This uses three "pumper" threads to actively copy the parent process's stdio independently (to prevent deadlock). Unfortunately this is giving us two problems. First, the input does not close automatically when the sub-process voluntarily exits. Second, the streams to the child process do not buffer and flush properly.

                  我正在寻找能够使我们的 require("os").system() 命令按预期工作的解决方案.

                  I'm looking for solutions that would make our require("os").system() command work as one would expect.

                  该项目位于 http://narwhaljs.org

                  相关代码:

                  • http://github.com/tlrobinson/narwhal/blob/d147c160f11fdfb7f3c0763acf352b2b0e2713f7/lib/os.js#L10
                  • http://github.com/tlrobinson/narwhal/blob/d147c160f11fdfb7f3c0763acf352b2b0e2713f7/engines/rhino/lib/os-engine.js#L37

                  推荐答案

                  不确定这是否是你要找的,但你可以通过 system 函数"https://github.com/twall/jna/" rel="nofollow noreferrer">JNA 库:

                  Not sure if this is what you're looking for, but you can invoke the C system function through the JNA library:

                  public class System {
                    public interface C extends Library {
                      C INSTANCE = (C) Native.loadLibrary(
                          (Platform.isWindows() ? "msvcrt" : "c"), C.class);
                  
                      public int system(String format);
                    }
                  
                    public static void main(String[] args) {
                      C.INSTANCE.system("vi");
                    }
                  }
                  

                  无论如何,粗略测试在 Windows 上运行.

                  Cursory testing worked on Windows, anyhow.

                  这篇关于实施“系统"Java中的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                  <tfoot id='TjYH9'></tfoot>

                      <tbody id='TjYH9'></tbody>
                    <legend id='TjYH9'><style id='TjYH9'><dir id='TjYH9'><q id='TjYH9'></q></dir></style></legend>
                  • <small id='TjYH9'></small><noframes id='TjYH9'>

                  • <i id='TjYH9'><tr id='TjYH9'><dt id='TjYH9'><q id='TjYH9'><span id='TjYH9'><b id='TjYH9'><form id='TjYH9'><ins id='TjYH9'></ins><ul id='TjYH9'></ul><sub id='TjYH9'></sub></form><legend id='TjYH9'></legend><bdo id='TjYH9'><pre id='TjYH9'><center id='TjYH9'></center></pre></bdo></b><th id='TjYH9'></th></span></q></dt></tr></i><div id='TjYH9'><tfoot id='TjYH9'></tfoot><dl id='TjYH9'><fieldset id='TjYH9'></fieldset></dl></div>

                        • <bdo id='TjYH9'></bdo><ul id='TjYH9'></ul>