stdin

Python: Execute scp, stdin for password not working

僤鯓⒐⒋嵵緔 提交于 2019-12-07 12:40:36
I'm trying the following from subprocess import Popen, PIPE Popen(["scp", "-B","user@url:file", "."], stdin=PIPE, shell=False).communicate(input="password") But I still get the password promt, and no password is sent. I know I can use scp with keys, but this is not what I need. Any help? scp interacts with the terminal directly, rather than reading from STDIN , You can't pass the password via a pipe, it security matter for scp and it's the same for sftp, ssh. you can try it in you terminal like this (and it will not work): echo "password" | scp me@localhost:test . As others have said, scp (and

Why aren't scanf(“%*[^\n]\n”); and scanf(“%*[^\n]%*c”); clearing a hanging newline?

最后都变了- 提交于 2019-12-07 11:36:27
问题 After a call to scanf("%d", &variable); we are left with a newline hanging at the stdin , which should be cleared before a call to fgets , or we end up feeding it a newline and making it return prematurely. I've found answers suggesting using scanf("%*[^\n]%*c"); after the first call to scanf to discard the newline and others suggesting using scanf("%*[^\n]\n"); . Theoretically, both should work: The first would consume everything that isn't a newline (but not including the newline itself)

Continuously exchange data using python-shell

别来无恙 提交于 2019-12-07 11:10:21
问题 I need to run some python scripts from node. Since my python scripts use complex structures I figured would be better if I only loaded those structures once and then run some the specific scripts (tasks) using the structures. On node I want to run a script forever (or until I say it can terminate) and keep sending on-demand messages to this script. This script would create a process, using python multiprocessing , to run the specific task and start listening again. A use case would be: Node

How do I avoid processing an empty stdin with python?

北城以北 提交于 2019-12-07 10:48:52
问题 The sys.stdin.readline() waits for an EOF (or new line) before returning, so if I have a console input, readline() waits for user input. Instead I want to print help and exit with an error if there is nothing to process, not wait for user input. Reason: I'm looking to write a python program with command line behaviour similar to grep . Test cases: No input and nothing piped, print help $ argparse.py argparse.py - prints arguments echo $? # UNIX echo %ERRORLEVEL% # WINDOWS 2 Command line args

How to read piped content in C?

余生颓废 提交于 2019-12-07 07:19:31
问题 I want to be able to do this: $ echo "hello world" | ./my-c-program piped input: >>hello world<< I know that isatty should be used to detect if stdin is a tty or not. If it’s not a tty, I want to read out the piped contents — in the above example, that’s the string hello world . What’s the recommended way of doing this in C? Here’s what I got so far: #include <stdio.h> #include <unistd.h> int main(int argc, char* argv[]) { if (!isatty(fileno(stdin))) { int i = 0; char pipe[65536]; while(-1 !=

Reading line by line from STDIN without blocking

女生的网名这么多〃 提交于 2019-12-07 06:33:32
问题 Basically, I'm looking to read lines from STDIN, but I don't want to block while waiting for new data. Almost like using a stream with a timeout. $stdin = fopen('php://stdin', 'r'); do { $line = fgets($stdin); // No input right now if (empty($line)) { // Do something before waiting for more input } } while (1); 回答1: Figured it out, use stream_set_blockingDocs to disable blocking. Sets $line to false when no input is available. 来源: https://stackoverflow.com/questions/4966365/reading-line-by

How to write unit tests for Inquirer.js?

此生再无相见时 提交于 2019-12-07 04:55:56
问题 I was wondering how to write unit tests for the npm package Inquirer.js, which is a tool to make CLI package more easily. I have read this post but I was't able to make it works. Here is my code that needs to be tested: const questions = [ { type: 'input', name: 'email', message: "What's your email ?", }, { type: 'password', name: 'password', message: 'Enter your password (it will not be saved neither communicate for other purpose than archiving)' } ]; inquirer.prompt(questions).then(answers

wkhtmltopdf relative paths in HTML with redirected in/out streams won't work

笑着哭i 提交于 2019-12-07 03:18:25
问题 I am using wkhtmltopdf.exe (version 0.12.0 final) to generate pdf files from html files, I do this with .NET C# My problem is getting javascript, stylesheets and images to work by only specifying relative paths in the html. Right now I have it working if I use absolute paths. But it doesn't work with relative paths, which makes the whole html generation a bit to complicated. I have boiled what I do down to the following example: string CMDPATH = @"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf

Write to stdin of a running process in windows

橙三吉。 提交于 2019-12-07 02:33:50
问题 I want to write data to an existing process's stdin from an external process in Windows. I found similar questions for Linux, but I want to know how I can do the same in Windows. How to write data to existing process's STDIN from external process? How do you stream data into the STDIN of a program from different local/remote processes in Python? https://serverfault.com/questions/443297/write-to-stdin-of-a-running-process-using-pipe I tried with this code but I got an error. I also tried

Determine if Stdin has data with Go

[亡魂溺海] 提交于 2019-12-07 02:32:45
问题 Is there a way to check if the input stream ( os.Stdin ) has data? The post Read from initial stdin in GO? shows how to read the data, but unfortunately blocks if no data is piped into the stdin. 回答1: os.Stdin is like any other "file", so you can check it's size: package main import ( "fmt" "os" ) func main() { file := os.Stdin fi, err := file.Stat() if err != nil { fmt.Println("file.Stat()", err) } size := fi.Size() if size > 0 { fmt.Printf("%v bytes available in Stdin\n", size) } else { fmt