标签: pipe

如何使用Bash将stdout和stderr重定向并附加到文件中?

要将stdout重定向到Bash中的截断文件,我知道要使用:

cmd > file.txt
Run Code Online (Sandbox Code Playgroud)

要在Bash中重定向stdout,追加到文件,我知道要使用:

cmd >> file.txt
Run Code Online (Sandbox Code Playgroud)

要将stdoutstderr重定向到截断的文件,我知道要使用:

cmd &> file.txt
Run Code Online (Sandbox Code Playgroud)

如何重定向附加到文件的stdoutstderrcmd &>> file.txt不适合我.

linux bash redirect pipe stream

1440
推荐指数
8
解决办法
70万
查看次数

如何管stderr,而不是stdout?

我有一个程序可以将信息写入stdoutstderr,并且我需要grep通过什么来到stderr,而忽略了stdout.

我当然可以分2步完成:

command > /dev/null 2> temp.file
grep 'something' temp.file
Run Code Online (Sandbox Code Playgroud)

但我宁愿能够在没有临时文件的情况下做到这一点.有没有任何智能管道技巧?

bash grep stdout pipe stderr

933
推荐指数
8
解决办法
38万
查看次数

将Windows cmd标准输出和stderr重定向到单个文件

我正在尝试将DOS命令的所有输出(stdout + stderr)重定向到单个文件:

C:\>dir 1> a.txt 2> a.txt
The process cannot access the file because it is being used by another process.
Run Code Online (Sandbox Code Playgroud)

是可能的,还是应该重定向到两个单独的文件?

windows command-line cmd pipe

656
推荐指数
7
解决办法
44万
查看次数

在Bash中重定向stderr和stdout

我想将进程的stdout和stderr重定向到单个文件.我怎么用Bash做到这一点?

bash shell redirect pipe

635
推荐指数
10
解决办法
66万
查看次数

在Bash中管道输出和捕获退出状态

我想执行Bash中长时间运行的命令,都捕获它的退出状态,并且发球它的输出.

所以我这样做:

command | tee out.txt
ST=$?
Run Code Online (Sandbox Code Playgroud)

问题是变量ST捕获退出状态tee而不是命令.我怎么解决这个问题?

请注意,命令长时间运行并将输出重定向到文件以便以后查看它对我来说不是一个好的解决方案.

error-handling bash shell pipe

400
推荐指数
11
解决办法
16万
查看次数

检索subprocess.call()的输出

如何使用subprocess.call()?获取进程的输出?

传递StringIO.StringIO对象stdout会出现此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 444, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 588, in __init__
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 945, in _get_handles
    c2pwrite = stdout.fileno()
AttributeError: StringIO instance has no attribute 'fileno'
>>> 
Run Code Online (Sandbox Code Playgroud)

python subprocess pipe stringio

248
推荐指数
7
解决办法
36万
查看次数

如何检测我的shell脚本是否通过管道运行?

如何从shell脚本中检测其标准输出是否被发送到终端或者是否通过管道传输到另一个进程?

举个例子:我想添加转义代码来着色输出,但只有在交互式运行时,而不是在管道输出时,类似于什么ls --color.

bash shell pipe

239
推荐指数
5
解决办法
6万
查看次数

如何在将屏幕保持在屏幕上的同时管道?(而不是输出文件)

我想在保持屏幕的同时管道程序的标准输出.

通过一个简单的例子(echo这里使用仅用于说明目的):

$ echo 'ee' | foo
ee < - 我希望看到的输出

我知道tee可以将stdout复制到文件中,但这不是我想要的.
$ echo 'ee' | tee output.txt | foo

我试过
$ echo 'ee' | tee /dev/stdout | foo但是因为tee输出到了/dev/stdout管道,所以它不起作用foo

bash shell stdout pipe output

214
推荐指数
5
解决办法
7万
查看次数

如何在管道中使用`subprocess`命令

我想subprocess.check_output()ps -A | grep 'process_name'.我尝试了各种解决方案,但到目前为止没有任 有人可以指导我怎么做吗?

python linux subprocess pipe

214
推荐指数
6
解决办法
20万
查看次数

如何将find命令返回的文件列表传递给cat以查看所有文件

我正在做一个find然后获取文件列表.如何将其传输到另一个实用程序cat(以便cat显示所有这些文件的内容),并且基本上需要grep从这些文件中获取内容.

unix pipe find

194
推荐指数
6
解决办法
28万
查看次数