stdout

Run Java class file from PHP script on a website

别说谁变了你拦得住时间么 提交于 2019-12-17 03:27:14
问题 I have a website and want to be able to allow the user to run a Java file on the server from the website. I want the user to click a button which will run the Java file on the server AND anything printed to standard-out by the Java program will be printed out on the website for the user to see. How can this be done (call Java program from PHP and feed the standard out from the Java file back to the PHP website in real time)? Update: Thanks for the answers on how to run the Java program from

Run Java class file from PHP script on a website

跟風遠走 提交于 2019-12-17 03:26:46
问题 I have a website and want to be able to allow the user to run a Java file on the server from the website. I want the user to click a button which will run the Java file on the server AND anything printed to standard-out by the Java program will be printed out on the website for the user to see. How can this be done (call Java program from PHP and feed the standard out from the Java file back to the PHP website in real time)? Update: Thanks for the answers on how to run the Java program from

Python 2.x - Write binary output to stdout?

拥有回忆 提交于 2019-12-17 02:49:11
问题 Is there any way to write binary output to sys.stdout in Python 2.x? In Python 3.x, you can just use sys.stdout.buffer (or detach stdout, etc...), but I haven't been able to find any solutions for Python 2.5/2.6. EDIT, Solution : From ChristopheD's link, below: import sys if sys.platform == "win32": import os, msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) EDIT: I'm trying to push a PDF file (in binary form) to stdout for serving up on a web server. When I try to write the file using

Silence the stdout of a function in Python without trashing sys.stdout and restoring each function call

三世轮回 提交于 2019-12-17 02:28:50
问题 Is there a way in Python to silence stdout without wrapping a function call like following? Original Broken Code: from sys import stdout from copy import copy save_stdout = copy(stdout) stdout = open('trash','w') foo() stdout = save_stdout Edit: Corrected code from Alex Martelli import sys save_stdout = sys.stdout sys.stdout = open('trash', 'w') foo() sys.stdout = save_stdout That way works but appears to be terribly inefficient. There has to be a better way. Any ideas? 回答1: Assigning the

catching stdout in realtime from subprocess

雨燕双飞 提交于 2019-12-17 02:08:26
问题 I want to subprocess.Popen() rsync.exe in Windows, and print the stdout in Python. My code works, but it doesn't catch the progress until a file transfer is done! I want to print the progress for each file in real time. Using Python 3.1 now since I heard it should be better at handling IO. import subprocess, time, os, sys cmd = "rsync.exe -vaz -P source/ dest/" p, line = True, 'start' p = subprocess.Popen(cmd, shell=True, bufsize=64, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout

How to pipe stderr, and not stdout?

為{幸葍}努か 提交于 2019-12-16 19:44:55
问题 I have a program that writes information to stdout and stderr , and I need to grep through what's coming to stderr , while disregarding stdout . I can of course do it in 2 steps: command > /dev/null 2> temp.file grep 'something' temp.file but I would prefer to be able to do this without temp files. Are there any smart piping tricks? 回答1: First redirect stderr to stdout — the pipe; then redirect stdout to /dev/null (without changing where stderr is going): command 2>&1 >/dev/null | grep

Unicode output in Python's stdout when running from cmd.exe [duplicate]

强颜欢笑 提交于 2019-12-14 04:22:31
问题 This question already has answers here : Python, Unicode, and the Windows console (13 answers) Closed 6 years ago . I am running Windows 7 and its console has been configured to use Consolas font, which gives me a possibility of Unicode output. The ability to read Unicode in console has been proved by me many times for programs such as Far Manager: both Cyrillics and German äöü letters can be read on the same console in the same string without encoding switching. Now about Python. I am trying

Get process output without blocking

爱⌒轻易说出口 提交于 2019-12-14 03:57:28
问题 I want to get a process' output ( Git.exe to be exact) and convert it to a String object. Previously sometimes my code was blocked. Then I figured out that it's because the process' ErrorStream has some output and I have to manually capture that (which I'm not interested in). I changed my code to this: public static String runProcess(String executable, String parameter) { try { String path = String.format("%s %s", executable, parameter); Process pr = Runtime.getRuntime().exec(path); // ignore

Compile a C/C++ Program and store standard output in a File via Python

与世无争的帅哥 提交于 2019-12-14 03:36:21
问题 Let's say I have a C/C++ file named userfile.c . Using Python, how can I invoke the local gcc compiler so that the file is compiled and an executable is made? More specifically, I would like to provide some input (stdin) via some file input.txt and I want to save the standard output into another file called output.txt . I saw some documentation that I will need to use subprocess, but I'm not sure how to call that and how to provide custom input. 回答1: A simple solution will be as given below:

Send messages from child process to parent

帅比萌擦擦* 提交于 2019-12-14 03:11:04
问题 I am executing the parent code. I then do a fork and then execvpe. The new program that i "execvpe" throws a lot of console messages and i want to hide those. Is it possible for me to redirect all my stdout and stderr messages in the child process onto a file? I tried a close(1) so that i dont dump messages on console (stdout) and that didnt help 回答1: pid_t pid = fork(); /* Child process */ if (pid == 0) { /* Open log file */ int log = creat("logfile", 0644); /* Redirect stdout to log file */