标签: pipe

Perl代码-管道“ |” 在`open()`语句中

我在Perl .pl文件中有以下代码。您是否认为此代码有任何问题(我不明白它的工作方式,因为第二行中有一个“ |”字符,而后面没有命令)

while ( $temp ne "" ) {
        open( PS, "ps -ef | grep deploy.sh | grep ssh | grep -v grep|" );
        $temp = <PS>;
        close(PS);
        print "The Deploy scripts are still running.  Now sleeping 20\n";
        sleep 20;
}
Run Code Online (Sandbox Code Playgroud)

perl file-io grep pipe while-loop

0
推荐指数
2
解决办法
4179
查看次数

当stdin是别的什么时,可以从键盘读取Go程序吗?

我有一个Go流程,通过管道接受输入.

tail -f something.foo | 去运行myprog.go

由于stdin是管道的输出,我找不到在myprog.go中读取键盘输入的方法.这可能吗?

我考虑在myprog.go中执行tail命令,但是我想避免在myprog.go崩溃并且无法终止另一个进程时创建另一个进程.

stdin pipe go

0
推荐指数
1
解决办法
162
查看次数

为什么grep给出"二进制文件(标准输入)匹配"?

#include <stdio.h>

int main()
{
    FILE* cmd = popen("grep Hello", "w");   
    fwrite("Hello\n", 6, 6, cmd);
    fwrite("Hillo\n", 6, 6, cmd);
    fwrite("Hello\n", 6, 6, cmd);   
    pclose(cmd);
}
Run Code Online (Sandbox Code Playgroud)

上述程序输出:

二进制文件(标准输入)匹配

为什么grep会给出消息,以及如何修复它?

c api io file pipe

0
推荐指数
1
解决办法
1605
查看次数

正确的代码测试但与sed一起使用时不匹配

为什么如下

$ echo "test\|String" | sed 's/(?!\||\\)./&./g'
test\|String
Run Code Online (Sandbox Code Playgroud)

不生产:

t.e.s.t.\|S.t.r.i.n.g.
Run Code Online (Sandbox Code Playgroud)

测试了正则表达式代码,它在我的测试中正确选取字符串

我希望它能做到以下几点:

$ echo "test\|String" | sed 's/(?!\||\\)./&./g'
t.e.s.t.\|S.t.r.i.n.g.
Run Code Online (Sandbox Code Playgroud)

regex sed pipe

0
推荐指数
1
解决办法
30
查看次数

如何穿越线路?

我有一个脚本,其中包含这样一行:

curl example.com | grep "some words | xargs mkdir | ad --nauseum

我的问题是,我是否可以在重定向输出时将其分成多行(或者这种情况是否有更好的模式?)

bash pipe

0
推荐指数
1
解决办法
43
查看次数

"cat a | cat b"忽略了a的内容

管道的正式定义表明左侧文件的STDOUT将立即通过管道传送到正确文件的STDIN.我有两个文件,hello.txthuman.txt. cat hello.txt返回Hellocat human.txt返回I am human.如果我这样做cat hello.txt | cat human.txt,不应该返回Hello I am human吗?相反,我正在看command not found.我是shell脚本的新手.有人可以解释一下吗?

linux bash pipe

0
推荐指数
1
解决办法
84
查看次数

去exec.Command() - 运行包含管道的命令

以下工作并打印命令输出:

out, err := exec.Command("ps", "cax").Output()
Run Code Online (Sandbox Code Playgroud)

但是这个失败了(退出状态为1):

out, err := exec.Command("ps", "cax | grep myapp").Output()
Run Code Online (Sandbox Code Playgroud)

有什么建议?

pipe exec go

0
推荐指数
2
解决办法
2718
查看次数

bash将管道中的值返回bash

我们有一个脚本,带有返回码.例如

#!/bin/bash
exit 42
Run Code Online (Sandbox Code Playgroud)

哪个工作正常:

$ ./script ; echo $?
42
Run Code Online (Sandbox Code Playgroud)

但如果我去:

$ bash << EOF
./script ; echo $?
EOF
0
Run Code Online (Sandbox Code Playgroud)

所以它打印0,而人们会期望它仍然打印42

bash pipe

0
推荐指数
1
解决办法
101
查看次数

C - stdin,unix管道和EOF

我正在编写一个应用程序,它首先从unix管道接收数据,然后提示用户输入.我似乎无法弄清楚为什么在提示用户输入之前管道的输入似乎没有正确关闭.感觉我在这里缺少一些非常基本的东西.

我曾尝试提出了冲洗标准输入所有的例子在这里没有成功.也似乎有可能相关,但我还没有设法提取任何相关的答案.

#include <stdio.h>
#include <stdlib.h>

#define BUFSZ 1024

int main(void) {

    char *buf = calloc(BUFSZ, sizeof(char));

    while(fgets(buf, BUFSZ, stdin)) { printf("Pipe input: %s", buf); }

    printf("Enter input: ");
    fgets(buf, BUFSZ, stdin);
    printf("User input: %s", buf);

    free(buf);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

用法和输出示例:

$ cat testdata2 | ./a.out
Pipe input: testdata testdata
Pipe input: testdata testdata2
Pipe input: testdata testdata3
Pipe input: testdata testdata4
Pipe input: testdata testdata5
Pipe input: testdata testdata6
Pipe input: testdata testdata7
Enter input: …
Run Code Online (Sandbox Code Playgroud)

c pipe c99

0
推荐指数
1
解决办法
261
查看次数

Angular2如何使用管道改变年龄

我想创建一个可以将年份(1992年)改为年龄(26岁)(韩国时代)的管道

我想我应该加载当前年份(2017年),减去1992年并加上+1

但我不知道如何用管道来实现这一点.

我提前感谢您的帮助.

pipe angular

0
推荐指数
1
解决办法
2295
查看次数

标签 统计

pipe ×10

bash ×3

c ×2

go ×2

angular ×1

api ×1

c99 ×1

exec ×1

file ×1

file-io ×1

grep ×1

io ×1

linux ×1

perl ×1

regex ×1

sed ×1

stdin ×1

while-loop ×1