stdin

Nodejs Child Process: write to stdin from an already initialised process

こ雲淡風輕ζ 提交于 2019-11-28 17:46:07
I am trying to spawn an external process phantomjs using node's child_process and then send information to that process after it was initialized, is that possible? I have the following code: var spawn = require('child_process').spawn, child = spawn('phantomjs'); child.stdin.setEncoding = 'utf-8'; child.stdout.pipe(process.stdout); child.stdin.write("console.log('Hello from PhantomJS')"); But the only thing I got on the stdout is the initial prompt for phantomjs console. phantomjs> So it seems the child.stdin.write is not making any effect. I am not sure I can send additional information to

Reading console input in Kotlin

倾然丶 夕夏残阳落幕 提交于 2019-11-28 17:29:24
I am attempting to accept input from the console in Kotlin but it is difficult because I am not too sure about the syntax. I begin with the main fun main(args: Array<String>) { } WHAT should I enter after this? I am aware that the println() and readline() are involved but I do not know how to structure them. Objective: prompt user to enter a number, the number entered is multiplied by 6, program returns the result to the console display. Here are A+B examples in Kotlin reading from stdin: fun main() { val (a, b) = readLine()!!.split(' ') println(a.toInt() + b.toInt()) } or fun main(vararg args

How to make a bash function which can read from standard input?

别等时光非礼了梦想. 提交于 2019-11-28 17:23:21
问题 I have some scripts that work with parameters, they work just fine but i would like them to be able to read from stdin, from a pipe for example, an example, suppose this is called read: #!/bin/bash function read() { echo $* } read $* Now this works with read "foo" "bar" , but I would like to use it as: echo "foo" | read How do I accomplish this? 回答1: You can use <<< to get this behaviour. read <<< echo "text" should make it. Test with readly (I prefer not using reserved words): function

Reading an integer from standard input

独自空忆成欢 提交于 2019-11-28 16:56:17
How do I use the fmt.Scanf function in Go to get an integer input from the standard input? If this can't be done using fmt.Scanf , what's the best way to read a single integer? http://golang.org/pkg/fmt/#Scanf All the included libraries in Go are well documented. That being said, I believe func main() { var i int _, err := fmt.Scanf("%d", &i) } does the trick An alternative that can be a bit more concise is to just use fmt.Scan : package main import "fmt" func main() { var i int fmt.Scan(&i) fmt.Println("read number", i, "from stdin") } This uses reflection on the type of the argument to

Programmatically read from STDIN or input file in Perl

删除回忆录丶 提交于 2019-11-28 16:18:13
What is the slickest way to programatically read from stdin or an input file (if provided) in Perl? ennuikiller while (<>) { print; } will read either from a file specified on the command line or from stdin if no file is given If you are required this loop construction in command line, then you may use -n option: $ perl -ne 'print;' Here you just put code between {} from first example into '' in second Ron This provides a named variable to work with: foreach my $line ( <STDIN> ) { chomp( $line ); print "$line\n"; } To read a file, pipe it in like this: program.pl < inputfile The "slickest" way

Read from File, or STDIN

心不动则不痛 提交于 2019-11-28 15:57:29
I've written a command line utility that uses getopt for parsing arguments given on the command line. I would also like to have a filename be an optional argument, such as it is in other utilities like grep, cut etc. So, I would like it to have the following usage tool -d character -f integer [filename] How can I implement the following? if a filename is given, read from the file. if a filename is not given, read from STDIN. In the simplest terms: import sys # parse command line if file_name_given: inf = open(file_name_given) else: inf = sys.stdin At this point you would use inf to read from

Read input.txt file and also output.bmp file from terminal (C-programming)

≡放荡痞女 提交于 2019-11-28 14:22:00
I have to do an assignment where I have to write a C-Programm, where it gets the input-file-name from the console as command line parameter. It should move the data from the input.txt file (the input file has the information for the bmp file - color etc.) to the generated output.png file. The 20 20 parameters stand for width and height for the output.png image. So the console-request for example (tested on Linux) will look like this: ./main input.txt output.bmp 20 20 I know that this code reads an input.txt File and puts it on the screen. FILE *input; int ch; input = fopen("input.txt","r"); ch

Flush/Clear System.in (stdin) before reading

妖精的绣舞 提交于 2019-11-28 14:19:54
At work, we have 5 RFID readers attached to a PC running Linux. The readers are all recognized as keyboards and send their input (what they read form the Chip) as an key-input-event sequence. To be able to tell which reader send what sequence, I'm doing a raw-read over /dev/input/XX and get their input this way. The problem with this is, that the send keyboard-events generated by the RFID readers are still "in" stdin and when I try to read from System.in via Scanner (input should be generated by a normal keyboard this time), I first get the "pending" input from the readers (which consists of

Not able to send commands to cmd.exe process

邮差的信 提交于 2019-11-28 14:06:22
问题 I am trying to send commands to an open cmd.exe process using StandardInput.WriteLine(str) , however none of the commands seem to be sent. First I open a process, with a global variable p ( Process p ). p = new Process() { StartInfo = { CreateNoWindow = true, UseShellExecute = false, RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true, FileName = @"cmd.exe", Arguments = "/C" //blank arguments } }; p.Start(); p.WaitForExit(); After, I try to send a command

How to inherit stdin and stdout in python by using os.execv()

放肆的年华 提交于 2019-11-28 14:04:48
First, I wrote a c++ code as follows: #include <cstdio> int main() { int a,b; while(scanf("%d %d",&a,&b) == 2) printf("%d\n",a+b); return 0; } I use g++ -o a a.cpp to complie it. Afterwards, I wrote python code as follows: import os,sys sys.stdin = open("./data.in","r") sys.stdout = open("./data.out","w") pid = os.fork() if pid == 0: cmd = ["./a","./a"] os.execv(cmd[0],cmd) However, the data.out file contains nothing. That is to say, the child process did not inherit stdin and stdout from his parent process. But when I wrote a c++ code as follows: #include<unistd.h> #include<cstdio> int main()