stdin

How to write in Java to stdin of ssh?

坚强是说给别人听的谎言 提交于 2019-12-19 08:08:05
问题 Everything works fine on the command line, but when I translate what I want into Java, the receiving process never gets anything on stdin. Here's what I have: private void deployWarFile(File warFile, String instanceId) throws IOException, InterruptedException { Runtime runtime = Runtime.getRuntime(); // FIXME(nyap): Use Jsch. Process deployWarFile = runtime.exec(new String[]{ "ssh", "gateway", "/path/to/count-the-bytes"}); OutputStream deployWarFileStdin = deployWarFile.getOutputStream();

How to write in Java to stdin of ssh?

心已入冬 提交于 2019-12-19 08:07:18
问题 Everything works fine on the command line, but when I translate what I want into Java, the receiving process never gets anything on stdin. Here's what I have: private void deployWarFile(File warFile, String instanceId) throws IOException, InterruptedException { Runtime runtime = Runtime.getRuntime(); // FIXME(nyap): Use Jsch. Process deployWarFile = runtime.exec(new String[]{ "ssh", "gateway", "/path/to/count-the-bytes"}); OutputStream deployWarFileStdin = deployWarFile.getOutputStream();

How to write in Java to stdin of ssh?

天大地大妈咪最大 提交于 2019-12-19 08:07:16
问题 Everything works fine on the command line, but when I translate what I want into Java, the receiving process never gets anything on stdin. Here's what I have: private void deployWarFile(File warFile, String instanceId) throws IOException, InterruptedException { Runtime runtime = Runtime.getRuntime(); // FIXME(nyap): Use Jsch. Process deployWarFile = runtime.exec(new String[]{ "ssh", "gateway", "/path/to/count-the-bytes"}); OutputStream deployWarFileStdin = deployWarFile.getOutputStream();

Does python's sys.stdin.read() block?

纵饮孤独 提交于 2019-12-19 07:18:28
问题 I'm adapting this Django management command for my own purposes. The script is a simple while-loop daemon that reads from sys.stdin (line 152, in command.handle() ) according to a protocol and writes results to sys.stdout. I would expect sys.stdin.read() to block until it receives something, but I find that when I run this script, it eats up 100% CPU before any data has been sent or received. Does sys.stdin.read(n) block? If not, how can I make this daemon more polite? Is time.sleep(s) safe

Does python's sys.stdin.read() block?

孤人 提交于 2019-12-19 07:18:19
问题 I'm adapting this Django management command for my own purposes. The script is a simple while-loop daemon that reads from sys.stdin (line 152, in command.handle() ) according to a protocol and writes results to sys.stdout. I would expect sys.stdin.read() to block until it receives something, but I find that when I run this script, it eats up 100% CPU before any data has been sent or received. Does sys.stdin.read(n) block? If not, how can I make this daemon more polite? Is time.sleep(s) safe

How do I read a single String from standard input?

♀尐吖头ヾ 提交于 2019-12-19 05:23:10
问题 There isn't straightforward instruction on receiving a string as a variable in the std::io documentation, but I figured this should work: use std::io; let line = io::stdin().lock().lines().unwrap(); But I'm getting this error: src\main.rs:28:14: 28:23 error: unresolved name `io::stdin` src\main.rs:28 let line = io::stdin.lock().lines().unwrap(); ^~~~~~~~~ Why? I'm using a nightly Rust v1.0. 回答1: Here's the code you need to do what you are trying (no comments on if it is a good way to go about

Ignore backspace key from stdin

こ雲淡風輕ζ 提交于 2019-12-19 03:16:13
问题 I want to make a program that forces it's user to input text but doesn't allow him to erase any of it, what's a simple way of doing it in C? The only thing I've got is (c = getchar()) != EOF && c != '\b' which doesn't work. Any ideas? 回答1: POSIX - unix version #include <sys/types.h> #include <termios.h> #include <stdio.h> #include <string.h> int main() { int fd=fileno(stdin); struct termios oldtio,newtio; tcgetattr(fd,&oldtio); /* save current settings */ memcpy(&newtio, &oldtio, sizeof

Ignore backspace key from stdin

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 03:16:05
问题 I want to make a program that forces it's user to input text but doesn't allow him to erase any of it, what's a simple way of doing it in C? The only thing I've got is (c = getchar()) != EOF && c != '\b' which doesn't work. Any ideas? 回答1: POSIX - unix version #include <sys/types.h> #include <termios.h> #include <stdio.h> #include <string.h> int main() { int fd=fileno(stdin); struct termios oldtio,newtio; tcgetattr(fd,&oldtio); /* save current settings */ memcpy(&newtio, &oldtio, sizeof

Write function result to stdin

一曲冷凌霜 提交于 2019-12-19 03:01:09
问题 I'm trying to write the results of a function to stdin. This is the code : def testy(): return 'Testy !' import sys sys.stdin.write(testy()) And the error I get is : Traceback (most recent call last): File "stdin_test2.py", line 7, in <module> sys.stdin.write(testy()) io.UnsupportedOperation: not writable I'm not completely sure, is this the right way of doing things ? 回答1: You could mock stdin with a file-like object? import sys import StringIO oldstdin = sys.stdin sys.stdin = StringIO

Why do I have to press Ctrl+D twice to close stdin?

◇◆丶佛笑我妖孽 提交于 2019-12-18 19:08:21
问题 I have the following Python script that reads numbers and outputs an error if the input is not a number. import fileinput import sys for line in (txt.strip() for txt in fileinput.input()): if not line.isdigit(): sys.stderr.write("ERROR: not a number: %s\n" % line) If I get the input from stdin, I have to press Ctrl + D twice to end the program. Why? I only have to press Ctrl + D once when I run the Python interpreter by itself. bash $ python test.py 1 2 foo 4 5 <Ctrl+D> ERROR: not a number: