stderr

Can't get stdout/stderr from (Python) subprocess.check_output()

Deadly 提交于 2019-12-23 22:14:33
问题 I'm trying to get the message from a git add command, to print to a log file later on. import subprocess import os filename = 'test.txt' # Add changes add_cmd = """git add "%s" """ % filename os.system(add_cmd) a = subprocess.check_output(add_cmd, shell=True, stderr=subprocess.STDOUT) The os.system() call shows in screen: fatal: Not a git repository (or any of the parent directories): .git which is correct, since this folder is not a git repo. But the subprocess.check_output() call fails with

Merge stdout and stderr in Popen

三世轮回 提交于 2019-12-23 21:47:54
问题 In Ruby's popen/spawn, how do I merge both STDOUT and STDERR as a single stream wihthout resorting to using >2&1 ? In Python, this would be: >>> import subprocess >>> subprocess.check_output('my_prog args', stderr=subprocess.STDOUT, shell=True) Note the stderr argument. I use Open3 - as I don't want just stdout - but it already separates them into two streams. 回答1: Using the code from your other question, here you go: cmd = 'a_prog --arg ... --arg2 ...' Open3.popen2({"MYVAR" => "a_value"}, "#

Linux里的2>&1的理解

狂风中的少年 提交于 2019-12-23 21:18:23
转载自: https://blog.csdn.net/ggxiaobai/article/details/53507530 我们在Linux下经常会碰到nohup command>/dev/null 2>&1 &这样形式的命令。首先我们把这条命令大概分解下首先就是一个nohup表示当前用户和系统的回话下的进城忽略响应HUP消息。&是把该命令以后台的job的形式运行。那么就剩下command>/dev/null 2>&1,command>/dev/null较好理解,/dev/null表示一个空设备,就是说吧command的执行结果重定向到空设备中,说白了就是不显示任何信息。那么2>&1又是什么含义? 2>&1 几个基本符号及其含义 /dev/null 表示空设备文件 0 表示stdin标准输入 1 表示stdout标准输出 2 表示stderr标准错误 从command>/dev/null说起 其实这条命令是一个缩写版,对于一个重定向命令,肯定是a > b这种形式,那么command > /dev/null难道是command充当a的角色,/dev/null充当b的角色。这样看起来比较合理,其实一条命令肯定是充当不了a,肯定是command执行产生的输出来充当a,其实就是标准输出stdout。所以command > /dev/null相当于执行了command 1 > /dev

Nodejs进阶:如何玩转子进程(child_process)

守給你的承諾、 提交于 2019-12-23 17:39:26
本文摘录自个人总结《Nodejs学习笔记》,更多章节及更新,请访问 github主页地址 。欢迎加群交流,群号 197339705 。 模块概览 在node中,child_process这个模块非常重要。掌握了它,等于在node的世界开启了一扇新的大门。熟悉shell脚本的同学,可以用它来完成很多有意思的事情,比如文件压缩、增量部署等,感兴趣的同学,看文本文后可以尝试下。 举个简单的例子: const spawn = require('child_process').spawn; const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); ls.on('close', (code) => { console.log(`child process exited with code ${code}`); }); 几种创建子进程的方式 注意事项: 下面列出来的都是异步创建子进程的方式,每一种方式都有对应的同步版本。 .exec() 、 .execFile() 、 .fork() 底层都是通过

Capturing and mailing bash script errors

流过昼夜 提交于 2019-12-23 17:33:45
问题 I have a script that I run nightly in cron to backup some postgres databases for several hosts on my network. I have a way of getting alerted that the script fails by leveraging the exit status, but it doesn't tell me WHY it failed. Based off the following code, how can I capture any errors that occur when the script is run, and email them to me so I can have a better understanding of what happened. FILEDATE=`date '+%Y-%m-%d'` BASEDIR=/u1/$1/db_dumps PGDUMP=/path/to/pg_dump HOST=$1 DB=$2 if [

Is there any way to redirect stderr output from a command run with “start” in the Windows command line?

久未见 提交于 2019-12-23 16:27:12
问题 I have a program that I want to automate runs for, since it takes awhile to complete. For some reason it outputs everything to stderr instead of stdout, and I'd like to check on its progress, so I find myself needing to redirect stderr output within a start command. I tried this: start "My_Program" "C:\Users\Me\my_program.exe" --some --presets --for --my_program.exe --output "C:\Users\Me\output_file_for_my_program" "C:\Users\Me\input_file_for_my_program" 2>"C:\Users\Me\my_program_output.log"

suppress/redirect stderr when calling python webrowser

与世无争的帅哥 提交于 2019-12-23 09:32:18
问题 I have a python program that opens several urls in seperate tabs in a new browser window, however when I run the program from the command line and open the browser using webbrowser.open_new(url) The stderr from firefox prints to bash. Looking at the docs I can't seem to find a way to redirect or suppress them I have resorted to using browserInstance = subprocess.Popen(['firefox'], stdout=log, stderr=log) Where log is a tempfile & then opening the other tabs with webbrowser.open_new. Is there

When debugging on Windows where does stderr go?

喜你入骨 提交于 2019-12-23 07:30:07
问题 When trying to debug a program on Windows I can't seem to find where the output I push to stderr is going. How do I get a hold of my stderr output? Is there a debugger-level setting (MSVC 9) I can change to redirect stderr to some part of the UI? Update: I have not looked into TRACE or OutputDebugString , but the code base is cross-platform, so platform-specific APIs, while not totally off the table, are secondary to a standards-compliant solution. 回答1: When you have a GUI process stderror

Windows console output not going to stdout nor stderr

烈酒焚心 提交于 2019-12-23 04:43:22
问题 Is it possible for any windows console app to output to console, while not outputting to stdout nor stderr? If yes - how to capture/redirect the output? I have a third party console app that I used to start from my C# app and redirect its stdandard error and output and read them from within my app. With an upgrade of this 3rd party app this approach stopped working. During investigation I found out that while it outputs to console; redirecting stderr to file caused it not to output to console

Suppress STDOUT from a Ruby C extension

本秂侑毒 提交于 2019-12-23 04:38:28
问题 I'm using the gem dep_selector in a project and can't figure out how to suppress the stdout from the library's C extensions. The code in question I want to suppress is here: https://github.com/RiotGames/knife_cookbook_dependencies/blob/master/lib/kcd/shelf.rb#L26 I tried this: real_stdout = $stdout $stdout = StringIO.new real_stderr = $stderr $stderr = StringIO.new puts "This gets suppressed correctly" selector.find_solution( ... ) # still prints to the terminal but I still get dep_selector