getpasswd functionality in Go?

The following is one of best ways to get it done. First get term package by go get golang.org/x/term package main import ( “bufio” “fmt” “os” “strings” “syscall” “golang.org/x/term” ) func main() { username, password, _ := credentials() fmt.Printf(“Username: %s, Password: %s\n”, username, password) } func credentials() (string, string, error) { reader := bufio.NewReader(os.Stdin) fmt.Print(“Enter … Read more

PHP standard input?

It is possible to read the stdin by creating a file handle to php://stdin and then read from it with fgets() for a line for example (or, as you already stated, fgetc() for a single character): <?php $f = fopen( ‘php://stdin’, ‘r’ ); while( $line = fgets( $f ) ) { echo $line; } fclose( … Read more

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

You need to pass also \n symbol to get your command work: 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’)\n”); child.stdin.end(); /// this call seems necessary, at least with plain node.js executable

Optional stdin in Python with argparse

The standard library documentation for argparse suggests this solution to allow optional input/output files: >>> parser = argparse.ArgumentParser() >>> parser.add_argument(‘infile’, nargs=”?”, type=argparse.FileType(‘r’), … default=sys.stdin) >>> parser.add_argument(‘outfile’, nargs=”?”, type=argparse.FileType(‘w’), … default=sys.stdout) >>> parser.parse_args([‘input.txt’, ‘output.txt’]) Namespace(infile=<_io.TextIOWrapper name=”input.txt” encoding=’UTF-8′>, outfile=<_io.TextIOWrapper name=”output.txt” encoding=’UTF-8′>) >>> parser.parse_args([]) Namespace(infile=<_io.TextIOWrapper name=”<stdin>” encoding=’UTF-8′>, outfile=<_io.TextIOWrapper name=”<stdout>” encoding=’UTF-8′>)

Read from File, or STDIN

The fileinput module may do what you want – assuming the non-option arguments are in args then: import fileinput for line in fileinput.input(args): print line If args is empty then fileinput.input() will read from stdin; otherwise it reads from each file in turn, in a similar manner to Perl’s while(<>).