- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个 ruby 脚本,它会写入一些输出,然后 exec
执行一个命令。该命令想要继承父级的文件描述符,因为它将从 stdin
中读取,以某种方式对其进行转换,然后将输出写入 stdout
。
举个例子
#!/usr/bin/env ruby
puts 'hello from parent'
exec 'tr', '[:lower:]', '[:upper:]'
如果我们直接在 shell 中运行它,我们会看到两行输出
$ echo 'hello, world!' | ./example.rb
hello from parent
HELLO, WORLD!
但是,如果进程的 stdout
被重定向,我们将丢失来自父进程的输出。
$ echo 'hello, world!' | ./example.rb | cat
HELLO, WORLD!
这是为什么?第一种情况和第二种情况有什么区别?
此外,如果我们将 ruby 脚本中的 exec
更改为 system
,那么这两行都会打印到终端。是什么导致了这种行为差异?
只是为了比较,一个大致相同的 bash 脚本似乎没有表现出相同的行为:
#!/bin/bash
echo 'hello from parent'
exec 'tr' '[:lower:]' '[:upper:]'
我们从父级和子级获得输出。
$ echo 'hello, world!' | ./example.sh | cat
hello from parent
HELLO, WORLD!
最佳答案
听起来 Ruby 在 exec
另一个程序之前不会刷新标准输出。您可以显式刷新标准输出。
[STEP 105] # cat example.rb
#!/usr/bin/env ruby
puts 'hello from parent'
$stdout.flush
exec 'tr', '[:lower:]', '[:upper:]'
[STEP 106] # echo 'hello, world!' | ./example.rb | cat
hello from parent
HELLO, WORLD!
[STEP 107] #
关于 ruby 脚本 : parent output missing after exec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48734971/
要在标题(或谷歌)中简洁地描述这是一个棘手的问题。我有一个分类表,其中某些列可能会根据置信度列为“已删除”。我想用“未识别”替换任何显示“已删除”的列,后跟第一列中未识别的值以行方式说“掉落”。因此,
我在 VSCode 上使用 pygame 模块,但遇到了 pygame 没有 init 成员的问题。我遵循了 this 的解决方案关联。我编辑了用户设置并添加了 "python.linting
我的问题是如何解决丢失的脚本太旧或丢失!! checking for a BSD-compatible install... /usr/bin/install -c checking whether
我正在使用带有启动器的 Spring Boot。当我错误配置启动器(缺少或定义了错误的值)时,它会打印“缺少 bean”错误消息,而不是“缺少值”。很难找到这个错误。 我的开胃菜看起来像 @Condi
我在 Django 1.7 中遇到问题,我正在尝试将用户保存到表中,但我收到一个错误,指出该表不存在。 这是我正在执行的代码: from django.conf import settings fro
我正在查看 EhCache 统计数据,我看到了这些数字: CacheMisses: 75977 CacheHits: 38151 InMemoryCacheMisses: 4843 InMemoryC
我正在尝试使用这些数据运行 lme 模型: tot_nochc=runif(10,1,15) cor_partner=factor(c(1,1,0,1,0,0,0,0,1,0)) age=runif(
我在 Microsoft Visual Studio C++ 中编写了一个程序,并为此使用了 SFML。我包含了程序所需的正确的 .dll 文件,并将它们复制到“发布”文件夹中。有效。整个程序在我的电
在设置新的Reaction CSR应用程序、一些样板库等过程中。在控制台中收到以下错误:。现在,我不会去修复一些我没有维护的包。我怎么才能找到真正的问题呢?Vite dev Build没有报告错误。
我正在上 React Native 类(class),然后使用 Flow 尝试纠正类(class)中的错误,因为讲师没有使用任何类型检查。 我在 Flow 中遇到了另一个错误,通过在互联网上进行长时间
我想删除图像标签正在寻找的缺失错误。我不想要 ult 标签占位符,试图故意将其保留为空白,直到我使用回形针浏览上传照片。 我已经将 url(:missing) 更改为许多其他内容,例如 nil 等。是
CREATE TABLE customer(customer_id NUMBER(6) PRIMARY KEY , customer_name VARCHAR2(40) NOT NULL , cust
我正在设置 invisible reCAPTCHA在我的 Web 应用程序中并且无法验证用户的响应。 (即使我传递了正确的 POST 参数) 我通过调用 grecaptcha.execute(); 以
我搜索了 these SO results找不到与我的问题相关的任何内容。我怀疑这可能是重复的。 我目前正在 .NET C# 3.5 中编写 Microsoft.Office.Interop.Exce
我在同一行收到两个错误。 Bridge *在 Lan 类中排名第一。我错过了什么? #include #include #include using namespace std; class L
首先,我看到了一些解决方案,但我没有理解它们。我是 QT 的新手,甚至谷歌也没有帮助我。英语不是我的母语 这是在QT Creator 5.6中调试后的报错信息 C2143: syntax error:
有没有办法把表1展开成表2?就是将start_no和end_no之间的每一个整数作为seq_no字段输出,取原表的其他字段组成新表(表2)。 表 1: date source market
我在 Excel (2016) 中制作了一个旭日形图,并希望为所有数据点添加标签。问题是,Excel 会自动丢弃一些标签: 似乎标签被删除是因为数据点太小或标签字符串太长。如何让 Excel 显示所有
在 R 3.0.2 中,missing() 函数可以告诉我们是否缺少形式参数。 如何避免硬编码传递给丢失的变量名称?例如在 demoargs <- function(a=3, b=2, d) {
我试图在 UI 上的某些功能中返回一个按钮,但出现了一个奇怪的错误。有人可以帮忙吗? var div = "View" 我得到的错误是: 参数列表后缺少 )。 最佳答案 onclick="javas
我是一名优秀的程序员,十分优秀!