我可以从popen完成流打开的bash
问题说明
据该男子页的popen()我打开一个/bin/sh...Is有办法,我可以重载这种行为开/斌/ bash shell,然后用Bash shell脚本进行交互?或者我需要打开一个PTY式接口做到这一点?
According to the man page for popen() I am opening a /bin/sh...Is there a way I can overload this behavior to open a /bin/bash shell and interact with BASH shell scripts? Or do I need to open a pty style connection to do that?
正确答案
如果你想在你传递给的popen
片段使用bash结构,可以调用的bash明确从SH。
If you want to use bash constructs in the snippet you pass to popen
, you can call bash explicitly from sh.
f = popen("exec bash -c 'shopt -s dotglob; cat -- *'", "r");
如果您需要的是bash里面的片段单引号,将它们作为'\\''
。所有其他字符字面过去了。
If you need single quotes inside the bash snippet, pass them as '\''
. All other characters are passed literally.
如果您有想要运行现有的bash脚本,只需指定其路径,与任何脚本或其他程序。确保脚本是可执行文件和#开始!的/ usr / bin中/ env的庆典
或#!/斌/庆典
。如果你有一个脚本,可能是非可执行文件(例如,由于便携性的Windows约束),则可以显式调用庆典:
If you have an existing bash script that you want to run, simply specify its path, same as any script or other program. Make sure that the script is executable and begins with #!/usr/bin/env bash
or #!/bin/bash
. If you have a script that may be non-executable (for example because of Windows portability constraints), you can invoke bash explicitly:
f = popen("exec bash myscript.bash", "r");
另外,编写自定义的的popen
样函数来调用你想要的(但这样做,只有当简单的解决方案是不理想的方案,因为它更难以得到对)。例如参见的popen()替代。
Alternatively, write your own custom popen
-like function that calls the program you want (but do that only if simpler solutions are not satisfactory, because it's more difficult to get right). See e.g. popen() alternative.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhchahhe
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20