stdout

Creating an Array in Bash with Quoted Entries from Command Output

跟風遠走 提交于 2019-12-30 19:29:54
问题 I'm having trouble forming a bash array from a standard output. I've boiled it down to this minimal example: ~$ a=($(echo '1 2 3 "foo bar"')) ~$ echo ${a[0]} 1 ~$ echo ${a[1]} 2 ~$ echo ${a[2]} 3 ~$ echo ${a[3]} "foo ~$ echo ${a[4]} bar" I believe what is happening is that "foo and bar" are considered separate items in the standard output, but the goal would be to consolidate those items into one for the array. Obviously, I could write a small loop to consolidate these terms into one, but I'm

Creating an Array in Bash with Quoted Entries from Command Output

被刻印的时光 ゝ 提交于 2019-12-30 19:29:18
问题 I'm having trouble forming a bash array from a standard output. I've boiled it down to this minimal example: ~$ a=($(echo '1 2 3 "foo bar"')) ~$ echo ${a[0]} 1 ~$ echo ${a[1]} 2 ~$ echo ${a[2]} 3 ~$ echo ${a[3]} "foo ~$ echo ${a[4]} bar" I believe what is happening is that "foo and bar" are considered separate items in the standard output, but the goal would be to consolidate those items into one for the array. Obviously, I could write a small loop to consolidate these terms into one, but I'm

Python logging module having a formatter causes AttributeError

家住魔仙堡 提交于 2019-12-30 09:00:40
问题 I am writing a terminal application, which, after passing in -v option, gets, unsurprisingly, verbose. I want to have the output available in the terminal, for easy testing (it gets redirected to a log file when running as cron anyways). However, python logging module doesn't allow me to write out the messages with corresponding levels when using a formatter. (Formatter is copied directly from Python Logging Cookbok) This behavior is not limited to Python3 only. Python2.7 raises the same

C: how to redirect stderr from System-command to stdout or file?

可紊 提交于 2019-12-30 06:24:18
问题 The shell command $ avrdude -c usbtiny outputs text to stderr. I cannot read it with commmands such as head-less-more cos it is not stdout. I want the text to stdout or to a file. How can I do it in C? I have tried to solve the problem by my last question but still unsolved. 回答1: I've not tried something like this in OpenBSD, but in at least a few *nix-like systems, you can do this using dup2 . #include <unistd.h> #include <stdio.h> int main(void) { fprintf(stderr, "This goes to stderr\n");

Custom C++ cout class - output to both console and log file

六月ゝ 毕业季﹏ 提交于 2019-12-30 04:37:07
问题 I'm working on a program that makes heavy use of "cout << strSomething;" to log information to the console. I need to modify the program so that all console output goes to both the console AND a file. Although I can modify the "cout <<" in our code, there are several large third party libraries that also use "cout <<"; those libraries cannot be modified due to their licenses - so modifying all references to "cout <<" is not a solution. Also, the use of "wtee.exe" isn't possible due to the

Shell script call from Android.mk, standard output and missing separator error

前提是你 提交于 2019-12-30 03:14:30
问题 I have a simple Android.mk file: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) $(shell ($(LOCAL_PATH)/echo_test.sh)) LOCAL_MODULE := libecho_test LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) The interesting thing that it does is to call the 'echo_test.sh' bash script. In the case when the contents of the script are #!/bin/bash echo 'echo is working' >&2 or #!/bin/bash echo 'echo is working' >/dev/null everything is OK. Things go wrong when the bash script is #!/bin/bash

Saving stdout from subprocess.Popen to file, plus writing more stuff to the file

廉价感情. 提交于 2019-12-30 00:27:14
问题 I'm writing a python script that uses subprocess.Popen to execute two programs (from compiled C code) which each produce stdout. The script gets that output and saves it to a file. Because the output is sometimes large enough to overwhelm subprocess.PIPE, causing the script to hang, I send the stdout directly to the log file. I want to have my script write something to the beginning and end of the file, and between the two subprocess.Popen calls. However, when I look at my log file, anything

Redirect but also display process output stream

▼魔方 西西 提交于 2019-12-29 08:41:24
问题 I am running a build, and I would like to be able to view the progress as it happens. But I would also like to save the output if the build has an error. I know I can use Process.UseShellExecute = false , and RedirectStandardOutput , but that's only part of the story. How can I do this? 回答1: Update As Greg mentions in the comments below, MSBuild can write out to a log file while also outputting to console out of the box. MSBuild [options] /filelogger /fileloggerparameters:LogFile=MSBuildLog

Nohup and Python -u : it still doesn't log data in realtime

喜你入骨 提交于 2019-12-29 07:49:47
问题 When launching a Python process, in background, with nohup python myscript.py > test.log 2>&1 < /dev/null & the problem is that stdout is buffered: the data is not written in realtime to test.log . The common solution to this problem is to flush periodically with sys.stdout.flush() , or even better, as suggested by this answer, to use python -u : nohup python -u myscript.py > test.log 2>&1 < /dev/null & But this is not enough . I noticed that it worked during a few hours, and then, it stopped

Issues intercepting subprocess output in real time

允我心安 提交于 2019-12-29 01:25:10
问题 I've spent about 6 hours on stack overflow, rewriting my python code and trying to get this to work. It just doesn't tho. No matter what I do. The goal: Getting the output of a subprocess to appear in real time in a tkinter text box. The issue: I can't figure out how to make the Popen work in real time. It seems to hang until the process is complete. (Run on its own, the process works completely as expected, so it's just this thing that has the error) Relevant code: import os import tkinter