stdin

getpasswd functionality in Go?

橙三吉。 提交于 2019-11-26 15:34:55
问题 Situation: I want to get a password entry from the stdin console - without echoing what the user types . Is there something comparable to getpasswd functionality in Go? What I tried: I tried using syscall.Read , but it echoes what is typed. 回答1: you can do this by execing stty -echo to turn off echo and then stty echo after reading in the password to turn it back on 回答2: The following is one of best ways to get it done. First get terminal package by go get golang.org/x/crypto/ssh package main

Read binary data from std::cin

北城余情 提交于 2019-11-26 15:31:13
What is the easiest way to read binary (non-formated) data from std::cin into either a string or a stringstream ? std::cin is not opened with ios_binary. If you must use cin, then you need to reopen it, which isn't part of the standard. Some ideas here: http://compgroups.net/comp.unix.programmer/How-can-I-reopen-std-cin-and-std-cout-in-binary-mode . Once it's binary, you can use cin.read() to read bytes. If you know that in your system, there is no difference between text and binary (and you don't need to be portable), then you can just use read without worrying. For windows, you can use the

How to send input to the console as if the user is typing?

99封情书 提交于 2019-11-26 14:44:06
问题 This is my problem. I have a program that has to run in a TTY, cygwin provides this TTY. When I redirect stdIn the program fails because it does not have a TTY. I cannot modify this program, and need some way of automating it. How can I grab the cmd.exe window and send it data and make it think the user is typing it? I'm using C#, I believe there is a way to do it with java.awt.Robot but I have to use C# for other reasons. 回答1: This sounds like a task for SendKeys(). It's not C#, but VBScript

How to make ssh receive the password from stdin

二次信任 提交于 2019-11-26 14:41:24
How can you make SSH read the password from stdin, which it doesn't do by default? You can't with most SSH clients. You can work around it with by using SSH API's, like Paramiko for Python. Be careful not to overrule all security policies. based on this post you can do: Create a command which open a ssh session using SSH_ASKPASS (seek SSH_ASKPASS on man ssh ) $ cat > ssh_session <<EOF export SSH_ASKPASS="/path/to/script_returning_pass" setsid ssh "your_user"@"your_host" EOF NOTE: To avoid ssh to try to ask on tty we use setsid Create a script which returns your password (note echo "echo ) $

Is it possible to set timeout for std::cin?

喜你入骨 提交于 2019-11-26 14:36:43
问题 Is it possible to set timeout for std::cin? For example, std::cin doesn't receive any data during 10 seconds - it throws an exception or returns an error. Edited: And what about timer from Boost library ? As far as I know, it is portable library. Is it possible to ask timer of Boost library to throw exceptions after predefined period of time? I guess it can solve this problem. 回答1: It isn't possible to set a time out for std::cin in a portable way. Even when resorting to non-portable

C read binary stdin

谁说我不能喝 提交于 2019-11-26 12:42:41
问题 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

Redirecting standard input\output in Windows PowerShell

。_饼干妹妹 提交于 2019-11-26 12:42:07
问题 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? 回答1: You can't hook a file directly to stdin, but you can still access stdin. Get-Content input.txt | ./program > output.txt 回答2: 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

How to pass variables as stdin into command line from PHP

和自甴很熟 提交于 2019-11-26 12:42:04
问题 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

Best practices with STDIN in Ruby?

余生长醉 提交于 2019-11-26 12:34:38
I want to deal with the command line input in Ruby: > cat input.txt | myprog.rb > myprog.rb < input.txt > myprog.rb arg1 arg2 arg3 ... What is the best way to do it? In particular I want to deal with blank STDIN, and I hope for an elegant solution. #!/usr/bin/env ruby STDIN.read.split("\n").each do |a| puts a end ARGV.each do |b| puts b end Jonke Following are some things I found in my collection of obscure Ruby. So, in Ruby, a simple no-bells implementation of the Unix command cat would be: #!/usr/bin/env ruby puts ARGF.read ARGF is your friend when it comes to input; it is a virtual file

nodejs how to read keystrokes from stdin

时间秒杀一切 提交于 2019-11-26 12:20:02
问题 Is it possible to listen for incoming keystrokes in a running nodejs script? If I use process.openStdin() and listen to its \'data\' event then the input is buffered until the next newline, like so: // stdin_test.js var stdin = process.openStdin(); stdin.on(\'data\', function(chunk) { console.log(\"Got chunk: \" + chunk); }); Running this, I get: $ node stdin_test.js <-- type \'1\' <-- type \'2\' <-- hit enter Got chunk: 12 What I\'d like is to see: $ node stdin_test.js <-- type \'1\'