标签: pipe

两个进程如何在没有 pipe() 的情况下相互通信?

鉴于此代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#define BUF_SIZE 256

int main()
{
    int fd1[2];
    int fd2[2];

    ssize_t numRead = -1;

    // remark : working under the assumption that the messages are of equal length

    const char* messageOne = "Hello world , I'm child number 1\n";
    const char* messageTwo = "Hello world , I'm child number 2\n";

    const unsigned int commLen = strlen(messageOne) + 1;

    char buf[BUF_SIZE];

    if (pipe(fd1) == -1)
    {
        printf("Error opening pipe 1!\n"); …
Run Code Online (Sandbox Code Playgroud)

c linux pipe named-pipes

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

意外的pipe()行为

我正在尝试通过管道进行2个进程通信.我等待孩子在管道中写一个字符,然后父母将从管道中读取字符并将其显示在屏幕上.问题是我成功地在管道中写入了字符(我做了一个测试,立即从中读取,我看到它在管道中),但是当父管从管道中读取时,它内部没有任何内容.我真的不明白为什么; 一切似乎都很好.

int PID, canal[2];
if(-1 == (PID = fork()))
{
    perror("Error");
    return 0;
}
if(-1 == pipe(canal))
{
    perror("Error");
    return 0;
}
if(PID == 0)
{
    close(canal[0]);
    printf("Child\n");
    char buffer = 'C';
    if( 0 == write(canal[1], &buffer, sizeof(char)))
        printf("Didn't write anything\n");
    close(canal[1]);
}
else
{
    char readBuffer;
    wait(NULL);
    printf("Parent\n");
    close(canal[1]);
    if(read(canal[0], &readBuffer, sizeof(char)))
    {
        printf("I read: ");
        printf("%c\n", readBuffer);
    }
    close(canal[0]);
}
Run Code Online (Sandbox Code Playgroud)

c linux posix fork pipe

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

Angular2如何舍入数字

嗨,我想把我计算的数字四舍五入到千位.

例如,如果我得到545,000,我希望它是550,000

我创造了一个管道

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({name: 'round'})
export class RoundPipe implements PipeTransform {

    transform(value: number): number {
        return Math.round(value);
    }
}
Run Code Online (Sandbox Code Playgroud)

似乎没有用

任何的想法?

pipe angular

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

在component.ts中使用Pipe

我有一个管道转换货币如下,

import { Pipe, PipeTransform } from '@angular/core';
import { LocalStorageService } from 'storage.service';
import { CurrencyUpdate } from 'update';
import { Observable } from 'rxjs/Observable';

@Pipe({name: 'currConvert'})
export class CurrConvertPipe implements PipeTransform {
    errorMessage: string;

    constructor(private currencyStorage: LocalStorageService, private currencyConversion: CurrencyUpdate) {
    }

    transform(value: number, toCurrency: string, baseCurrency: string): any {
        if (toCurrency && baseCurrency) {
            const outputRate = this.currencyStorage.getCurrencyRate(baseCurrency, toCurrency);
            if (!outputRate) {
                return this.currencyConversion.getExchangeRate(toCurrency, baseCurrency).map((rate: any) => {
                    const currency = {
                        fromCurrency: baseCurrency,
                        toCurrency,
                        exchangeRate: rate …
Run Code Online (Sandbox Code Playgroud)

pipe typescript angular

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

如何用角度2中的逗号分隔数千

在角度2或4中我希望数字用逗号分隔,当它在输入和用户输入时以及它只是打印时.您有任何想法或解决方案可以分享吗?提前谢谢你们.

pipe separator angular

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

C - 如何在只读取单个字符时检测管道中的EOF?

正如回答中所解释的那样,在编写进程关闭所有相关文件描述符EOF之后,我期待读者进程能够正确捕获.

但这并没有发生,这个程序最终陷入无休止的循环.父母等待孩子完成,孩子等待发出EOF封闭管道的信号.

为什么读者进程没有收到EOF

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

#define STRING_TO_SEND "Hello, world!\n"

int main() {
    int fd[2], i = 0;
    __pid_t pid;
    char _char;
    ssize_t nbytes;

    pipe(fd);
    pid = fork();

    if (pid == -1) {
        // Error
        perror("Error forking!");
        return EXIT_FAILURE;

    } else if (pid == 0) {

        // Child
        close(fd[1]);
        while ((nbytes = read(fd[0], &_char, 1)) != EOF) {
            if (nbytes == 0) …
Run Code Online (Sandbox Code Playgroud)

c pipe file-descriptor eof

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

使用管道替换Bash进程

假设我有一个文件t.txt,其中包含许多包含'a'的行.我很疑惑为什么这不起作用:

cat <(tail -f t.txt | grep a)
Run Code Online (Sandbox Code Playgroud)

上面的命令只是挂起而不打印任何内容,即使每行都有匹配.这是因为猫正在等待"尾巴"而不是"grep"的输出吗?我怎样才能解决这个问题?

顺便说一句,我尝试了另一种带有双重过程替换的变体:

cat <(grep a <(tail -f t.txt))
Run Code Online (Sandbox Code Playgroud)

这也挂起而不打印任何东西.

有人有线索吗?

linux bash pipe

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

在Perl中发送linux命令 - Grep管道传输到grep

基本代码:

my $ContentDate = `date -d '1 hour ago' '+%Y-%m-%e %H:'`;
my $Fail2banNo = `grep Ban /var/log/fail2ban.log | grep $ContentDate | wc -l`;

if (($Fail2banNo > $fail2ban)) {

} else {

}
Run Code Online (Sandbox Code Playgroud)

为什么Perl不会正确完成这些命令?$ fail2ban已经定义为0,所以这不是问题.

fail2ban.log确实包含一个应匹配的行(当从shell运行命令时它匹配):

2018-07-19 xx:11:50,200 fail2ban.actions[3725]: WARNING [iptables] Ban x.x.x.x
Run Code Online (Sandbox Code Playgroud)

我一直得到的错误是:

grep: 10:: No such file or directory
sh: -c: line 1: syntax error near unexpected token `|'
sh: -c: line 1: ` | wc -l'
Argument "" isn't numeric in numeric gt (>) at /usr/local/bin/tmgSupervision.pl line 3431. …
Run Code Online (Sandbox Code Playgroud)

linux perl grep command pipe

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

是否有相当于C#的| VB.Net中的运算符?

在VB.Net中是否有相当于C#的管道运算符(|)?

我从这里有一些代码如何为我的应用程序为所有用户创建的文件授予完全权限?

它在C#中,我想将其转换为VB.Net.我到目前为止(VS说有一个错误:| InheritanceFlags.ContainerInherit):

Sub ZugriffsrechteEinstellen()

    Dim dInfo As New DirectoryInfo(strPfadSpracheINI)
    Dim dSecurity As New DirectorySecurity

    dSecurity = dInfo.GetAccessControl()
    dSecurity.AddAccessRule(New FileSystemAccessRule(New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow))

    dInfo.SetAccessControl(dSecurity)

End Sub
Run Code Online (Sandbox Code Playgroud)

c# vb.net pipe equivalent operator-keyword

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

为什么我的子进程所在的程序需要用户在退出前键入“ Enter”?

我有以下程序:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <sys/wait.h>

int main()
{
    int p[2];
    char *argv[2];
    argv[0] = "wc";
    argv[1] = "-w";
    argv[2] = NULL;

    pipe(p);
    if (fork() == 0)
    {
        close(0);
        dup(p[0]);
        close(p[0]);
        close(p[1]);
        execvp(argv[0], argv);
    }
    else
    {
        close(p[0]);
        write(p[1], "hello world\n", 12);
    }

    fprintf(stdout, "hello world\n");
}

Run Code Online (Sandbox Code Playgroud)

当我运行它时:

$ gcc a.c
$ ./a.out
Run Code Online (Sandbox Code Playgroud)

我得到以下内容:

hello world
$ 2
_    // the cursor is flickering here
Run Code Online (Sandbox Code Playgroud)

输入后Enter …

c linux posix fork pipe

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