stdout

Define a new handle (Similar to STDOUT)

回眸只為那壹抹淺笑 提交于 2019-12-01 04:58:24
问题 I was looking at redirecting handles in batch, when I noticed this: Here is the link It mentions that handles 3-9 are undefined and can be defined by a program. Now I've read about doing this in C#, but I wondered if this was possible in cmd/batch - and if it is, what are its limitations/use. If it is not possible in cmd, how would I go about using this, and could it be a solution to outputting data to the screen and redirecting it to a file at the same time (a problem which has not been able

Integer File Descriptor “0” in open() - Python 3

冷暖自知 提交于 2019-12-01 04:17:27
In Python 3, it is possible to open a file object using an "integer file descriptor" with the format: stdout = open(1, "w") stdout.write("Hello World") # Prints Hello World stdout.close() Though, interestingly, I found that 0 is also a valid stream. If I put this in the file testio.py : stdout = open(0, "w") stdout.write("Foo Bar\n") stdout.close() And then run that code the output is: bash-3.2$ python3 testio.py Foo Bar Which seems just like stdout . However... bash-3.2$ python3 testio.py > testio.txt Foo Bar bash-3.2$ cat testio.txt So it seems that this is actually not stdout , but

Using standard io stream:stdin and stdout in a matlab exe

荒凉一梦 提交于 2019-12-01 04:08:32
问题 Question I want it to 'listen' to the standard input stream in a running (compiled) Matlab executable. This is how I believe it is done in c or a similar language: #include stdio.h fgets(line, 256, stdin) Or more elaborately, it it can be used as such: if (!fgets(line, 256, stdin)) return; if (line[0] == '\n') continue; sscanf(line, "%s", command); Answer For completeness I will leave the background and notes intact, but with the help of Amro and EitanT I have managed to work it out.

python - prevent IOError: [Errno 5] Input/output error when running without stdout

自闭症网瘾萝莉.ら 提交于 2019-12-01 04:04:52
I have a script that runs automatically on server through cronjob and it import and run several other scripts. Some of them use prints, which naturally creates IOError: [Errno 5] Input/output error because the script runs without any SSH / terminal connected, so there's no proper stdout setup. There are lots of questions about this subject but I couldn't find anyone that actually solve it, assuming I can't remove the print or change the executed scripts. I tried several things, including: class StdOut(object): def __init__(self): pass def write(self, string): pass sys.stdout = StdOut() sys

How to redirect all console output to a Swing JTextArea/JTextPane with the right encoding?

匆匆过客 提交于 2019-12-01 03:28:46
问题 I've been trying to redirect System.out PrintStream to a JTextPane. This works fine, except for the encoding of special locale characters. I found a lot of documentation about it (see for ex. mindprod encoding page), but I'm still fighting with it. Similar questions were posted in StackOverFlow, but the encoding wasn't addressed as far as I've seen. First solution: String sUtf = new String(s.getBytes("cp1252"),"UTF-8"); Second solution should use java.nio. I don't understand how to use the

How can I get the command-line output of a DOS tool using Perl?

帅比萌擦擦* 提交于 2019-12-01 00:02:17
I want to meassure the throughput of a link using Windows build-in FTP tool inside a Perl script. Therefore the script creates the following command script: open <ip> <username> <password> hash get 500k.txt quit Afterwards I run the command script using the following Perl code: system(@args); @args = ("ftp", "-s:c:\\ftp_dl.txt"); system(@args); If I run the command inside a DOS-box the output looks like this: ftp> open <ip> Connected to <ip> 220 "Welcome to the fast and fabulous DUFTP005 ftp-server :-) " User (<ip>:(none)): 331 Please specify the password. 230 Login successful. ftp> hash Hash

How to save the output of a console application

白昼怎懂夜的黑 提交于 2019-11-30 23:43:33
问题 I need advice on how to have my C# console application display text to the user through the standard output while still being able access it later on. The actual feature I would like to implement is to dump the entire output buffer to a text file at the end of program execution. The workaround I use while I don't find a cleaner approach is to subclass TextWriter overriding the writing methods so they would both write to a file and call the original stdout writer. Something like this: public

How can I read process output that has not been flushed?

允我心安 提交于 2019-11-30 23:36:07
问题 Consider this little programm be compiled as application.exe #include <stdio.h> int main() { char str[100]; printf ("Hello, please type something\n"); scanf("%[^\n]s", &str); printf("you typed: %s\n", str); return 0; } Now I use this code to start application.exe and fetch its output. #include <stdio.h> #include <iostream> #include <stdexcept> int main() { char buffer[128]; FILE* pipe = popen("application.exe", "r"); while (!feof(pipe)) { if (fgets(buffer, 128, pipe) != NULL) printf(buffer);

Redirect STDOUT and STDERR to socket in C?

笑着哭i 提交于 2019-11-30 22:41:31
I am trying to redirect STDOUT AND STDERR to a socket. I did: if(fork() == 0) { dup2(newsock, STDOUT_FILENO); dup2(newsock, STDERR_FILENO); execvp(); } Somehow, it only showed the first little part of the output. for example, it showed on "mkdir" when I try to execute ls or mkdir. What's the problem? I tried the flollowing it works, but I can only redirect one of STDOUT or STDERR close(1); dup(newsock); Thanks a lot. Your use of dup2() looks fine, so the problem is probably elsewhere. The simple program I threw together to test with does not have the issues you are experiencing, so I'll just

PHP CLI doesn't use stderr to output errors

空扰寡人 提交于 2019-11-30 22:32:31
问题 I'm running the PHP CLI through a NSTask in MacOS, but this question is more about the CLI itself. I'm listening to the stderr pipe, but nothing is output there no matter what file I try to run: If the file type is not a plain text, stdout sets to ? . If the file is a php script with errors, the error messages are still printed to stdout . Is there a switch to the interpreter to handle errors through stderr ? Do I have an option to detect errors other than parsing stdout ? 回答1: The display