stdin

plain-C stdin buffer garbage and newline-eaters

守給你的承諾、 提交于 2019-12-25 01:55:41
问题 I have a question concerning stdin buffer content inspection. This acclaimed line of code: int c; while((c = getchar()) != '\n' && c != EOF); deals efficiently with discarding stdin-buffer garbage, in case there is a garbage found. In case the buffer is empty, the program execution wouldn't go past it. Is there a way of checking if there is garbage in the stdin-buffer at all (no matter if it's there by user error, typeahead or whichever reason), and executing the "fflush-replacement line"

Redirect process standard input in Task

别说谁变了你拦得住时间么 提交于 2019-12-25 01:25:21
问题 I'm trying to start a process In C# (Java.exe running a jar file) in a seperate thread, and redirect it's StandardInput, StandardError and StandardOutput. I've successfully redirect StandardError and StandardOutput, but I am having problems with StandardInput. I'm starting the process this way: Action<object> MyAction = (object obj) => { MyProcess.Start(); MyProcess.WaitForExit(); }; Task MyTask = new Task(MyAction); MyTask.Start(); What I need then is to be able to, in my windows forms

Python argparse mutually exclusive with stdin being one of the options

◇◆丶佛笑我妖孽 提交于 2019-12-24 23:46:15
问题 I would like my script to receive these mutually exclusive input options: an input file containing a JSON ( script.py -i input.json ); a string containing a JSON ( script.py '{"a":1}' ); a JSON from stdin ( echo '{"a":1}' | script.py or cat input.json | script.py ). and these mutually exclusive output options : an output file containing a JSON; a JSON in stdout. So I tried with this code import json,sys,argparse parser = argparse.ArgumentParser(description='Template for python script managing

can I redirect the output of this program to script?

偶尔善良 提交于 2019-12-24 22:53:05
问题 I'm running a binary that manages a usb device. The binary file, when executed outputs results to a file I specify. Is there any way in python the redirect the output of a binary to my script instead of to a file? I'm just going to have to open the file and get it as soon as this line of code runs. def rn_to_file(comport=3, filename='test.bin', amount=128): os.system('capture.exe {0} {1} {2}'.format(comport, filename, amount)) it doesn't work with subprocess either from subprocess import

I need a way to read in floats twice in C. Each time ended by <Ctrl>-d

懵懂的女人 提交于 2019-12-24 18:32:20
问题 I need to read in the coefficients (as floats) of a polynomial and mark the end by ctrl-d. Then I need to read in x values and display f(x). Also ending that with ctrl-d. So far I have tried it with the scanf function. Reading the coefficients work well but after typing ctrl-d the first time, scanf will not read in x values. #include <stdio.h> int main(){ int count = 0; float poly[33]; while(scanf("%f", &poly[count]) != EOF){ // reading the coeffs count++; } printf("Bitte Stellen zur

Piping Binary Data from Python GUI to c++ and back again

北城余情 提交于 2019-12-24 17:27:31
问题 I have been working on a project that pipes data back and forth between a QGIS plugin written in Python and some image processing code I have written in C++. After some community help via the following 2 questions I have gotten a console based sample code working that simulates an image, pipes it over to my C++ code, does some nontrivial processing, and then pipes it back and unpacks it correctly. I am having trouble porting this to a GUI style code. previous questions for reference: Data

unable to use scanf twice for scanning a string and then scanning a char

被刻印的时光 ゝ 提交于 2019-12-24 15:15:13
问题 I tried using scanf twice for scanning a string and then scanning a char. It scans string first and does not execute the second scanf . When I use both %s and %c in a single scanf it works perfectly. Can you tell me why this happens? #include<stdio.h> int main() { char s[100],ch; scanf("%s",s); scanf("%c",&ch); //this does not work printf("%s %c",s,ch); return 0; } another program which works #include<stdio.h> int main() { char s[100],ch; scanf("%s %c",s,&ch); //this works! printf("%s %c",s

Sublime Text 2 + SublimeREPL allowing user input

时光怂恿深爱的人放手 提交于 2019-12-24 13:19:12
问题 I'd like to set up Sublime Text 2 (or 3 if recommended) to allow user input (raw_input() or input() within the files.). To clarify, I've had this work before! I want to be able to write and execute all code within one window/tab. I have installed sublimeREPL correctly but yet whenever I use either raw_input() or input() I receive the following error: EOFERROR: EOF when reading a line I've had it setup correctly and it worked perfectly before, but it's been a long time and I cannot reproduce

PHP email Piping get 'to' field

拟墨画扇 提交于 2019-12-24 09:04:06
问题 I am trying to use email piping with PHP. I have it working except I can't get the 'To' field. I am using the following PHP code: #!/usr/bin/php -q <?php // read from stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); $to1 = explode ("\nTo: ", $email); $to2 = explode ("\n", $to1[1]); $to = str_replace ('>', '', str_replace('<', '', $to2[0])); } fclose($fd); mail('email@example.com','From my email pipe!','"' . $to . '"'); ?> If I use a email

Run java.exe through ProcessBuilder leads to application hanging?

不羁岁月 提交于 2019-12-24 07:16:39
问题 I have the following code: ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java", "-cp", "project_folder\\target\\classes", "package.ExternalProcess"); Process p = pb.start(); OutputStream processOutputStream = p.getOutputStream(); IOUtils.write("1" + System.lineSeparator(), processOutputStream); InputStream processInputStream = p.getInputStream(); System.out.println("--1--"); System.out.println(process.isAlive()); // outputs true String result = IOUtils