stdin

Redirecting standard input\\output in Windows PowerShell

社会主义新天地 提交于 2019-11-27 04:11:43
What is the required syntax to redirect standard input/output on Windows PowerShell? On Unix, we use: $./program <input.txt >output.txt How do I execute the same task in PowerShell? You can't hook a file directly to stdin, but you can still access stdin. Get-Content input.txt | ./program > output.txt For output redirection you can use: command > filename Redirect command output to a file (overwrite) command >> filename APPEND into a file command 2> filename Redirect Errors Input redirection works in a different way. For example see this Cmdlet http://technet.microsoft.com/en-us/library

C read binary stdin

旧街凉风 提交于 2019-11-27 04:05:22
I'm trying to build an instruction pipeline simulator and I'm having a lot of trouble getting started. What I need to do is read binary from stdin, and then store it in memory somehow while I manipulate the data. I need to read in chunks of exactly 32 bits one after the other. How do I read in chunks of exactly 32 bits at a time? Secondly, how do I store it for manipulation later? Here's what I've got so far, but examining the binary chunks I read further, it just doesn't look right, I don't think I'm reading exactly 32 bits like I need. char buffer[4] = { 0 }; // initialize to 0 unsigned long

How to pass variables as stdin into command line from PHP

家住魔仙堡 提交于 2019-11-27 03:57:40
I am trying to write a PHP script that uses the pdftk app to merge an XFDF with a PDF form and output the merged PDF to the user. According to the pdftk documentation, I can pass the form data in via stdin and have the PDF output to the stdout stream. The normal, file-not-stream way to use pdftk from the command line is: pdftk blankform.pdf fill_form formdata.xfdf output filledform.pdf to use streams on the command line, you'd enter: pdftk blankform.pdf fill_form - output - I have a couple of problems: 1) I have gotten pdftk to return output via stdout using an xfdf file (instead of stdin )

Read from file or stdin

与世无争的帅哥 提交于 2019-11-27 03:35:10
I am writing a utility which accepts either a filename, or reads from stdin. I would like to know the most robust / fastest way of checking to see if stdin exists (data is being piped to the program) and if so reading that data in. If it doesn't exist, the processing will take place on the filename given. I have tried using the following the test for size of stdin but I believe since it's a stream and not an actual file, it's not working as I suspected it would and it's always printing -1 . I know I could always read the input 1 character at a time while != EOF but I would like a more generic

Is it possible to distribute STDIN over parallel processes?

我只是一个虾纸丫 提交于 2019-11-27 03:28:02
问题 Given the following example input on STDIN: foo bar bar baz === qux bla === def zzz yyy Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel? So the example input above would result in 3 parallel processes (for example a command called do.sh) where each instance received a part of the data on STDIN, like this: do.sh (instance 1) receives this over STDIN: foo bar bar baz do.sh (instance 2) receives this over STDIN: qux bla do

Fastest method to generate big random string with lower Latin letters

二次信任 提交于 2019-11-27 03:24:52
问题 I'm trying to solve this problem from Timus Online Judge. To solve this problem you need generate a sequence of 1 000 000 lowercase Latin letters and write it to stdin in 1 second. It is easy to solve this problem with C++ or Java. I have python solution here: import os from random import randint s = ''.join(chr(97 + randint(0, 25)) for i in range(1000000)) os.write(1, bytes(s, 'utf8')) It takes 1.7s: $ time python3.3 1219.py > /dev/null real 0m1.756s user 0m1.744s sys 0m0.008s And I got

How to read from stdin line by line in Node

江枫思渺然 提交于 2019-11-27 02:50:05
I'm looking to process a text file with node using a command line call like: node app.js < input.txt Each line of the file needs to be processed individually, but once processed the input line can be forgotten. Using the on-data listener of the stdin, I get the input steam chunked by a byte size so I set this up. process.stdin.resume(); process.stdin.setEncoding('utf8'); var lingeringLine = ""; process.stdin.on('data', function(chunk) { lines = chunk.split("\n"); lines[0] = lingeringLine + lines[0]; lingeringLine = lines.pop(); lines.forEach(processLine); }); process.stdin.on('end', function()

How do file descriptors work?

拈花ヽ惹草 提交于 2019-11-27 02:42:24
Can someone tell me why this does not work? I'm playing around with file descriptors, but feel a little lost. #!/bin/bash echo "This" echo "is" >&2 echo "a" >&3 echo "test." >&4 The first three lines run fine, but the last two error out. Why? File descriptors 0, 1 and 2 are for stdin, stdout and stderr respectively. File descriptors 3, 4, .. 9 are for additional files. In order to use them, you need to open them first. For example: exec 3<> /tmp/foo #open fd 3. echo "test" >&3 exec 3>&- #close fd 3. For more information take a look at Advanced Bash-Scripting Guide: Chapter 20. I/O Redirection

Why can't we read one character at a time from System.in?

本小妞迷上赌 提交于 2019-11-27 02:03:53
The program below prints each character written on standard in, but only after a new-line has been written (at least on my system!). public class Test { public static void main(String[] args) throws java.io.IOException { int c; while ((c = System.in.read()) != -1) System.out.print((char) c); } } This prevents people from writing stuff like "Press any key to continue" and forces something like "Press enter to continue." What is the underlying reason for this? Is it a limitation of Java? Is this behavior system-dependent (I'm on Ubuntu)? How does it work on Mac? Windows? Is it dependent on the

Recognizing arrow keys with stdin

对着背影说爱祢 提交于 2019-11-27 02:00:38
问题 is it possible to have a cross-platform way to handle backspace and arrows keys within a C or OCaml program? Actually an OCaml solution would be appreciated but many standard unix functions are wrapped directly to corresponding API calls so there's should be no problem in porting a C solution. What I'm going to achieve is to catch the arrow keys to override its behaviour inside the shell (by repropting last line or operations like these). I think that this thing falls before the actual