stdin

Read a line of input faster than fgets?

梦想与她 提交于 2019-12-30 03:08:27
问题 I'm writing a program where performance is quite important, but not critical. Currently I am reading in text from a FILE* line by line and I use fgets to obtain each line. After using some performance tools, I've found that 20% to 30% of the time my application is running, it is inside fgets . Are there faster ways to get a line of text? My application is single-threaded with no intentions to use multiple threads. Input could be from stdin or from a file. Thanks in advance. 回答1: You don't say

Read expression for grep from standard input

ε祈祈猫儿з 提交于 2019-12-30 00:27:15
问题 How can I make grep read the expression from standard input (stdin)? For example (the following doesn't work): grep -i -f &0 /path/to/text/file < "/regexp/" 回答1: Use -f with a single dash to denote the standard input: $ echo Content | grep -f - notice.html <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> ... Note: This has been tested with GNU grep - I am not sure if it's specified by POSIX. 来源: https://stackoverflow.com/questions/6641731/read-expression-for-grep-from

How to parse JSON from stdin at Native Messaging host?

ぃ、小莉子 提交于 2019-12-29 09:47:13
问题 Utilizing the code at How do I use a shell-script as Chrome Native Messaging host application as a template and given the file file.json which contains {"text":"abc"} following the code at Iterate over json with jq and the jq documentation $ cat file.json | jq --raw-output '.text' outputs abc Am not certain how to incorporate the pattern at this Answer while read -r id name date; do echo "Do whatever with ${id} ${name} ${date}" done< <(api-producing-json | jq --raw-output '.newList[] | "\(.id

.NET: Inject Data into Input-Buffer of Process

跟風遠走 提交于 2019-12-29 09:06:30
问题 I need to automate an command line application. It asks the user to enter a password. All my approches to send the password via STDIN failed. Now I am trying to do this with an wrapper-programm using .NET. I am starting the application creating a new process, setting the StartInfo -properties and then start the process: Dim app_path As String Dim app_args As String Dim myProcess As Process = New Process() myProcess.StartInfo.FileName = app_path myProcess.StartInfo.Arguments = app_args

How to read from std::cin until the end of the stream?

大城市里の小女人 提交于 2019-12-29 09:05:54
问题 My problem is, that I want to read the input from std::cin but don't know how long the input is. Also I have to char and can't use std::string . There are two ways I have to handle: a) The user inputs text and when he hits [ENTER] the program stops reading. b) The user redirects std::cin to a file (like .\a.oput < file ) which can hold multiple lines. Edit: Just noticed that std::cin.eof() is always false also in the case of reading form a file. For a) I could read until \n occures. For b)

java.util.scanner throws NoSuchElementException when application is started with gradle run

拜拜、爱过 提交于 2019-12-29 06:14:24
问题 I have a created a simple java "echo" application that takes a user's input and shows it back to them to demonstrate the issue. I can run this application without trouble using IntelliJ's internal "run" command, and also when executing the compiled java file produced by gradle build . However, if I try to execute the application using gradle run , I get a NoSuchElementException thrown from the scanner. I think gradle or the application plugin specifically is doing something strange with the

sys.stdin.readlines() hangs Python script

感情迁移 提交于 2019-12-29 06:09:50
问题 Everytime I'm executing my Python script, it appears to hang on this line: lines = sys.stdin.readlines() What should I do to fix/avoid this? EDIT Here's what I'm doing with lines : lines = sys.stdin.readlines() updates = [line.split() for line in lines] EDIT 2 I'm running this script from a git hook so is there anyway around the EOF? 回答1: This depends a lot on what you are trying to accomplish. You might be able do: for line in sys.stdin: #do something with line Of course, with this idiom as

How do you specify filenames within a zip when creating it on the command line from a pipe?

二次信任 提交于 2019-12-29 03:35:39
问题 I'm trying to create a zip file from file contents which are being piped in, e.g. mysql [params and query] | zip -q output.zip - This writes the zip correctly, but when you open the zip, the file within it is called "-". Is there any way of specifying what the filename of the piped in data should be within the zip? 回答1: From what i can gather you cannot do both with the zip command, i mean you cannot both specify the filenames and pipe the content. You can either pipe the contents and the

Is there a way to read standard input with JavaScript?

*爱你&永不变心* 提交于 2019-12-28 12:05:18
问题 I saw this for lots of other languages but not JavaScript. I'm trying to do problems like: this (codechef.com) and of course the programs need to be able to read standard in like C++ and other languages do. EDIT: Thanks for the answers. The primary reason I want this functionality is so I can answer the questions on CodeChef; Codechef sends multiple inputs to the files/programs that are the answers (and of course the programs have to respond in the required way for the answer to be correct).

Is there a way to read standard input with JavaScript?

血红的双手。 提交于 2019-12-28 12:03:47
问题 I saw this for lots of other languages but not JavaScript. I'm trying to do problems like: this (codechef.com) and of course the programs need to be able to read standard in like C++ and other languages do. EDIT: Thanks for the answers. The primary reason I want this functionality is so I can answer the questions on CodeChef; Codechef sends multiple inputs to the files/programs that are the answers (and of course the programs have to respond in the required way for the answer to be correct).