stdout

Capturing SSH output as variable in bash script

≯℡__Kan透↙ 提交于 2019-11-30 05:08:56
I've been struggling with this problem when writing a bash script. Basically, I want to measure the time of a program on a remote server, so I use the command: /usr/bin/time -f %e sh -c "my command > /dev/null 2>&1" to execute the program. However, it appears that I cannot capture the output of my command (SSH) to a variable at all. In fact, the result (time) keeps getting printed out to stdout. The full code is: respond=$(ssh ${fromNode} /usr/bin/time "-f" "%e" "'sh' '-c' 'virsh migrate --live ${VM} qemu+ssh://${toNode}/system --verbose > /dev/null 2>&1'") The value of respond is just empty,

How to Pipe Output to a File When Running as a Systemd Service?

試著忘記壹切 提交于 2019-11-30 04:18:37
I'm having trouble piping the STDOUT & STDERR to a file when running a program as a systemd service. I've tried adding the following to the .service file: ExecStart=/apppath/appname > /filepath/filename 2>&1 But this doesn't work. The output is ending up in /var/log/messages and is viewable using journalctl but I'd like a separate file. I've also tried setting StdOutput=tty but can't find a way of redirecting this to a file. Any help would be appreciated. systemd.service(5) says: ExecStart= Commands with their arguments that are executed when this service is started. So, systemd runs your

Concatenate strings, files and program output in Bash

烈酒焚心 提交于 2019-11-30 03:17:16
The use case is, in my case, CSS file concatenation, before it gets minimized. To concat two CSS files: cat 1.css 2.css > out.css To add some text at one single position, I can do cat 1.css <<SOMESTUFF 2.css > out.css This will end in the middle. SOMESTUFF To add STDOUT from one other program: sed 's/foo/bar/g' 3.css | cat 1.css - 2.css > out.css So far so good. But I regularly come in situations, where I need to mix several strings, files and even program output together, like copyright headers, files preprocessed by sed(1) and so on. I'd like to concatenate them together in as little steps

Python, logging print statements while having them print to stdout

谁说我不能喝 提交于 2019-11-30 02:26:10
I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If possible logging the user's input would be beneficial as well. I found this which somewhat answers my question but makes it where the "print" statement no longer prints to the command line Redirect Python 'print' output to Logger You can add this to your script: import sys sys

How to remove last character put to std::cout?

别等时光非礼了梦想. 提交于 2019-11-30 02:00:07
Is it possible on Windows without using WinAPI? You may not remove last character. But you can get the similar effect by overwriting the last character. For that, you need to move the console cursor backwards by outputting a '\b' (backspace) character like shown below. #include<iostream> using namespace std; int main() { cout<<"Hi"; cout<<'\b'; //Cursor moves 1 position backwards cout<<" "; //Overwrites letter 'i' with space } So the output would be H No. You can't without accessing the console's api that is never standard. This code does exactely that std::cout<<"\b \b"; 来源: https:/

Call another click command from a click command

被刻印的时光 ゝ 提交于 2019-11-30 00:54:20
问题 I want to use some useful functions as commands. For that I am testing the click library. I defined my three original functions then decorated as click.command : import click import os, sys @click.command() @click.argument('content', required=False) @click.option('--to_stdout', default=True) def add_name(content, to_stdout=False): if not content: content = ''.join(sys.stdin.readlines()) result = content + "\n\tadded name" if to_stdout is True: sys.stdout.writelines(result) return result

Should I output warnings to STDERR or STDOUT?

柔情痞子 提交于 2019-11-30 00:02:03
I'm making a script that handles a predefined set of data, outputting to a file. I want to pop up a warning when one datum (which is always "Regular" in every set that I've had access to) is different stating that this value is unhandled (since I don't know how it affects the data). Should I output this warning to stderr or stdout? If I saved the output of this script (i.e. stdout only) so that I could process it later, would that warning interfere with how the output is parsed? Moreover, if output is piped to another process, the warning should show up on the terminal, so the user sees it

Get live stdout from gevent-subprocess?

不打扰是莪最后的温柔 提交于 2019-11-29 22:32:40
问题 I'm trying to get the stdout of a process via POPEN as soon as it's there. With gevent 1.0 readline() and read() still block process and wait for process to finish. Any clues? And yes, I searched high and low for a simple solution. It has to be possible without threading, right? 回答1: import gevent from gevent.subprocess import Popen, PIPE def cron(): while True: print("cron") gevent.sleep(0.5) g = gevent.spawn(cron) def subp(): sub = Popen('sleep 1; ping www.google.com -c 2; sleep 5; uname',

does echo equal fputs( STDout )?

喜你入骨 提交于 2019-11-29 22:18:33
Does echo equal fputs( STDOUT ) , or does echo write to a different stream? I've used PHP for a while now, but I don't know very well what's actually happening on a lower level. According to PHP's manual page on wrappers , the answer is No. php://output php://output is a write-only stream that allows you to write to the output buffer mechanism in the same way as print() and echo(). print and echo write to php://output stream, whereas fputs(STDOUT) writes to php://stdout . I did a little test: <?php $output = fopen('php://output', 'w'); ob_start(); echo "regular echo\n"; fwrite(STDOUT, "writing

bash: redirect (and append) stdout and stderr to file and terminal and get proper exit status

牧云@^-^@ 提交于 2019-11-29 21:21:30
To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal, I do this: command 2>&1 | tee -a file.txt However, is there another way to do this such that I get an accurate value for the exit status? That is, if I test $? , I want to see the exit status of command , not the exit status of tee . I know that I can use ${PIPESTATUS[0]} here instead of $? , but I am looking for another solution that would not involve having to check PIPESTATUS . Perhaps you could put the exit value from PIPESTATUS into $? command 2>&1 | tee -a file.txt ; ( exit ${PIPESTATUS} )