stdin

PowerShell wrapper to direct piped input to Python script

℡╲_俬逩灬. 提交于 2019-12-02 09:44:02
问题 I'm trying to write a little tool that will let me pipe command output to the clipboard. I've read through multiple answers on Stack Overflow, but they didn't work for me, because they didn't include piping, or because they didn't use a function, or they just threw errors (or maybe I just messed up). I threw up my hands with PowerShell and decided to go with Python. I created a Python script called copyToClipboard.py : import sys from Tkinter import Tk if sys.stdin.isatty() and len(sys.argv)

How to end scanf by entering only one EOF

筅森魡賤 提交于 2019-12-02 09:09:41
问题 I am encoutering this problem. I am using while loop to scan string of numbers and need to end scanning and start proceeding the rest of my program. I just can't figure out, how to flush the stdin or do anything to not press Ctrl+D twice. I just need to send EOF only once to tell my loop to end. while (! feof (stdin)) {status=scanf ("%d", &array[i]); if ( (status != 1 && status != EOF) ) { printf("\nWrong input.\n"); return 1;} i++;} 回答1: Edit: it's bug 1190 on glibc, it was apparently done

fflush() function not working with stdin

允我心安 提交于 2019-12-02 08:54:32
问题 I'm sorry for this silly question. I have C program to prompt user to enter age and name and then print the age and name to the screen. This is my exercise that I read from book. This the program: #include <stdio.h> int main (void) { int age; char name[20]; puts("Enter your age:"); scanf("%d",&age); fflush(stdin); puts("Enter your name:"); scanf("%s",name); printf("Your age is %d\n",age); printf("Your name is %s\n",name); return 0; } When I enter extra characters to the first scanf() the

Twisted Python: Cannot write to a running spawned process

微笑、不失礼 提交于 2019-12-02 07:37:00
My question is, after spawning a process, the child process is looping to get data from its stdin. I would like to write new data to it using either Echo.Process.pipes[0].write(data) or Echo.Process.writeToChild(0,data), but both do not work. Would someone explain what's going on? Or how do I go around this problem? This is the error I got: --- <exception caught here> --- File "/usr/local/encap/python-2.6.4/lib/python2.6/site-packages/Twisted-9.0.0-py2.6-linux-x86_64.egg/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite why = getattr(selectable, method)() File "/usr/local/encap

read() stdin in c?

本小妞迷上赌 提交于 2019-12-02 07:29:53
I have a quick little question involving the read() command. I am really rusty in C, and unfortunately, my current assignment has me programming in C. We need to read stdin using the read() and not fgets and the like. So I have a simple while loop: int n, i; char buffer[257], *input; while((n=read(fileno(stdin), buffer, 256)) > 0) { buffer[n] ='\0'; if(buffer[n] = '\n') break; write(input, buffer, strlen(buffer)); } So I am not sure how to make this loop stop at the press of enter (end of line) so that's why I have the break code, though I don't know if that's done correctly. The whole

stdin stdout python: how to reuse the same input file twice?

余生颓废 提交于 2019-12-02 07:17:34
I am quite new to Python and even newer to stdin stdout method. Nevertheless I need to make my script usable for UNIX commands, in order to make it possible for example to process 2 input files at once with my script. This script works perfectly well with command line arguments: newlist = [] def f1() .... def f2(input_file): vol_id = sys.argv[3] for line in input_file: if ... : line = line.replace('abc','def') line = line.replace('id', 'id'+vol_id) .... newlist.append(line) return newlist def main(): if len(sys.argv) < 4: print 'usage: ./myscript.py [file_in... file_out... volume_id]' sys.exit

How to read input from the terminal using /dev/stdin and read.csv()?

点点圈 提交于 2019-12-02 07:14:52
问题 I'm using: R version 3.0.0 (2013-04-03) -- "Masked Marvel" Platform: x86_64-pc-linux-gnu (64-bit) I try to use read.csv to input a little CSV data snippet + header, directly from the terminal. I'm encountering a problem that may be related to R skips lines from /dev/stdin and read.csv, header on first line, skip second line but is different enough (the answers there don't explain what I see here) to warrant a separate question. R seems to skip the header line and treat the second (data) line

How to check if stdin buffer is empty at TCL?

回眸只為那壹抹淺笑 提交于 2019-12-02 06:52:36
问题 With fconfigure you can get and set channel options. -buffering specifies the type of buffering, and by default it is line for stdin . Is there a way to check if the buffer at stdin is empty or not? Please see this question: How to check if stdin is pending in TCL? 回答1: Obviously you could set the channel mode to non-blocking and read from it. If the read returns 0 length then nothing was available. However, I suspect you mean to test for data present but not a complete line given your

'git am < MyFix.patch' command error in Powershell

三世轮回 提交于 2019-12-02 06:36:48
How do we get this command to run on Powershell with out error : The '<' operator is reserved for future use. C:\Users\Me\my-git-repo > git am < MyFix.patch The '<' operator is reserved for future use. At line:1 char:9 + git am < <<<< MyFix.patch + CategoryInfo : ParserError: (<:OperatorToken) [],.. + FullyQualifiedErrorId : RedirectionNotSupported Derek Redfern Use either: Get-Content MyFix.patch | git am or: cmd /c 'git am < MyFix.patch' Both should work equally well. Windows Powershell simply doesn't support IO redirection with < for now, so you either need to pipe the text to stdin using |

readline() returns null in Java

微笑、不失礼 提交于 2019-12-02 06:27:49
问题 I'm trying to read the stdin in my Java program. I'm expecting a series of numbers followed by newlines, like: 6 9 1 When providing the input through the eclipse built-in console, everything goes well. But when using the Windows command line, the program prints: Received '6'. Received 'null'. Invalid input. Terminating. (This line is written by another function that does an Integer.parseint()). My code is: static String readLineFromStdIn(){ try{ java.io.BufferedReader stdin = new java.io