stderr

node.js child_process.spawn no stdout unless 'inherit'

心不动则不痛 提交于 2019-12-03 06:17:12
I'm trying to capture the stdout from a spawn ed child_process in node.js (0.10.29). Right now I'm just trying with ping The following code doesn't print (but does ping) var exec = require('child_process').exec; var spawn = require('child_process').spawn; var util = require('util') var ping = spawn('ping', ['127.0.0.1'], {stdio: 'pipe'}); ping.stdout.on('data', function(data){ util.print(data); }) ping.stderr.on('data', function(data){ util.print(data); }) If I change stdio: 'pipe' to stdio: 'inherit' and get rid of the stdout/stderr hooks like so: var ping = spawn('ping', ['127.0.0.2'],

python subprocess模块

妖精的绣舞 提交于 2019-12-03 05:23:11
import subprocess # # 默认接受['程序名','参数']的列表;shell=True表示直接调用系统的shell来执行字符串参数 # print(subprocess.run('dir',shell=True)) # 执行指定的命令,等待命令执行完成后返回一个包含执行结果的CompletedProcess类的实例。 # print(subprocess.call('dir',shell=True)) # 执行指定的命令,返回命令执行状态,其功能类似于os.system(cmd) # print(subprocess.check_call('dir',shell=True)) #执行指定的命令,如果执行成功则返回状态码,否则抛出异常。其功能等价于subprocess.run(..., check=True)。 # print(subprocess.check_output('dir',shell=True)) #执行指定的命令,如果执行状态码为0则返回命令执行结果(二进制字节形式的),否则抛出异常。 # print(subprocess.getoutput('dir')) # 接收字符串格式的命令,执行命令并返回执行结果,其功能类似于os.popen(cmd).read()和commands.getoutput(cmd)。 # print(subprocess

What are “cerr” and “stderr”?

坚强是说给别人听的谎言 提交于 2019-12-03 05:21:17
What is the difference between them and how are they used? Can anyone point me to examples? Specifically, how do you "write" to the stream in both cases and how do you recover and output (i.e. to the screen) the text that had been written to it? Also, the "screen" output is itself a stream right? Maybe I don't understand streams well enough. This can also be saved to a file of course, I know. Would all of these use fprintf / fscanf , etc? cerr is the C++ stream and stderr is the C file handle, both representing the standard error output. You write to them the same way you write to other

phantomjs pdf to stdout

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am desperately trying to output a PDF generated by phantomJS to stdout like here What I am getting is an empty PDF file, although it is not 0 in size, it displays a blank page. var page = require('webpage').create(), system = require('system'), address; address = system.args[1]; page.paperSize = {format: 'A4'}; page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); phantom.exit(); } else { window.setTimeout(function () { page.render('/dev/stdout', { format: 'pdf' }); phantom.exit(); }

pythonw.exe or python.exe?

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Long story short: pythonw.exe does nothing, python.exe accepts nothing (which one should I use?) test.py: print "a" CMD window: C:\path>pythonw.exe test.py C:\path> C:\path>python.exe test.py File "C:\path\test.py", line 7 print "a" ^ SyntaxError: invalid syntax C:\path> Please tell me what I'm doing terrible wrong. 回答1: If you don't want a terminal window to pop up when you run your program use pythonw.exe ; Otherwise, use python.exe Regarding the syntax error: print is now a function in 3.x So use instead: print("a") 回答2: To summarize and

How I can print to stderr in C?

青春壹個敷衍的年華 提交于 2019-12-03 01:51:00
问题 In C, Printing to stdout is easy, with printf from stdio.h . However, how can print to stderr? We can use fprintf to achieve it apparently, but its syntax seems strange. Maybe we can use printf to print to stderr? 回答1: The syntax is almost the same as printf . With printf you give the string format and its contents ie: printf("my %s has %d chars\n", "string format", 30); With fprintf it is the same, except now you are also specifying the place to print to: File *myFile; ... fprintf( myFile,

Python - Hive commands using Subprocess - empty results

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using subprocess to run hive commands in python, but am getting empty results. If i run the same commands from hive CLI, am getting results. query = "set hive.cli.print.header=true;use mydb;describe table1;" process = subprocess.Popen( ["ssh", "hadoop" , "hive", "-e", "%r" % query], stdout = subprocess.PIPE, stderr = subprocess.PIPE ) data = [line.split('\t') for line in process.stdout] cols = list(itertools.chain.from_iterable(data[:1])) df = pd.DataFrame(data[1:], columns = cols) print "==>"+df+"<----" It's returning empty dataframe.

AttributeError: StringIO instance has no attribute &#039;fileno&#039;

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: def captureOutput(self, func, *args, **kwargs): pass sys.stdout.flush() sys.stderr.flush() (outfd, fn) = tempfile.mkstemp() fout = os.fdopen(outfd, 'r') os.unlink(fn) (errfd, fn) = tempfile.mkstemp() ferr = os.fdopen(errfd, 'r') os.unlink(fn) try: oldstdout = os.dup(sys.stdout.fileno()) oldstderr = os.dup(sys.stderr.fileno()) os.dup2(outfd, sys.stdout.fileno()) os.dup2(errfd, sys.stderr.fileno()) try: ret = func(*args, **kwargs) finally: sys.stderr.flush() sys.stdout.flush() os.dup2(oldstdout, sys.stdout.fileno()) os.close(oldstdout) os.dup2

Python IDLE script does not show output of subprocess but cmd.exe does

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Python 2.7.6 and IDLE on Windows 7. I have 2 Python scripts: script.py: import subprocess, os, sys print("hello 1") mypath = os.path.abspath(__file__) mydir = os.path.dirname(mypath) start = os.path.join(mydir, "script2.py") subprocess.call([sys.executable, start, "param"]) print("bye 1") and script2.py that is being called by the previous script: import sys print "hello 2" print (sys.argv[1]) print "bye 2" If I run script.py with cmd.exe shell I get the expected result: C:\tests>python ./script.py hello 1 hello 2 param bye 2 bye 1

Error: Could not get the Java version. Is Java installed?

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I run Appium server: I try to run this code to post to Appium server: public class AndroidTest { private AppiumDriver driver; @Before public void setUp() throws Exception { // File classpathRoot = new File(System.getProperty("user.dir")); // File appDir = new File(classpathRoot, "../../../data/app/"); // File app = new File(appDir, "Facebook.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability("deviceName","10.0.0.9:5555"); capabilities