stdin

Write to child process' stdin in Rust?

做~自己de王妃 提交于 2020-12-31 05:54:05
问题 Rust's std::process::Command allows configuring the process' stdin via the stdin method, but it appears that that method only accepts existing files or pipes. Given a slice of bytes, how would you go about writing it to the stdin of a Command ? 回答1: You can create a stdin pipe and write the bytes on it. As Command::output immediately closes the stdin, you'll have to use Command::spawn . Command::spawn inherits stdin by default. You'll have to use Command::stdin to change the behavior. Here is

Write to child process' stdin in Rust?

柔情痞子 提交于 2020-12-31 05:51:49
问题 Rust's std::process::Command allows configuring the process' stdin via the stdin method, but it appears that that method only accepts existing files or pipes. Given a slice of bytes, how would you go about writing it to the stdin of a Command ? 回答1: You can create a stdin pipe and write the bytes on it. As Command::output immediately closes the stdin, you'll have to use Command::spawn . Command::spawn inherits stdin by default. You'll have to use Command::stdin to change the behavior. Here is

Write to child process' stdin in Rust?

你离开我真会死。 提交于 2020-12-31 05:50:08
问题 Rust's std::process::Command allows configuring the process' stdin via the stdin method, but it appears that that method only accepts existing files or pipes. Given a slice of bytes, how would you go about writing it to the stdin of a Command ? 回答1: You can create a stdin pipe and write the bytes on it. As Command::output immediately closes the stdin, you'll have to use Command::spawn . Command::spawn inherits stdin by default. You'll have to use Command::stdin to change the behavior. Here is

X86 read from stdin and write to stdout without referring the standard library

六月ゝ 毕业季﹏ 提交于 2020-12-30 03:56:06
问题 I'm a beginner in X86 assembly language. I know how to read from stdin and write to stdout using build-in functions, but I'm not sure how to do it with plain assembly code(i.e. manipulating registers and taking advantage of system calls). #include <stdio.h> #include <unistd.h> int main(){ /* copy input to output */ char buf[BUFSIZ]; int n; while ((n = read(0, buf, BUFSIZ)) > 0) write(1, buf, n); return 0; } This is the C code I wrote to first read from the standard input (represented by

X86 read from stdin and write to stdout without referring the standard library

做~自己de王妃 提交于 2020-12-30 03:55:50
问题 I'm a beginner in X86 assembly language. I know how to read from stdin and write to stdout using build-in functions, but I'm not sure how to do it with plain assembly code(i.e. manipulating registers and taking advantage of system calls). #include <stdio.h> #include <unistd.h> int main(){ /* copy input to output */ char buf[BUFSIZ]; int n; while ((n = read(0, buf, BUFSIZ)) > 0) write(1, buf, n); return 0; } This is the C code I wrote to first read from the standard input (represented by

X86 read from stdin and write to stdout without referring the standard library

廉价感情. 提交于 2020-12-30 03:55:33
问题 I'm a beginner in X86 assembly language. I know how to read from stdin and write to stdout using build-in functions, but I'm not sure how to do it with plain assembly code(i.e. manipulating registers and taking advantage of system calls). #include <stdio.h> #include <unistd.h> int main(){ /* copy input to output */ char buf[BUFSIZ]; int n; while ((n = read(0, buf, BUFSIZ)) > 0) write(1, buf, n); return 0; } This is the C code I wrote to first read from the standard input (represented by

Python basics: How to read N ints until '\n' is found in stdin

有些话、适合烂在心里 提交于 2020-12-29 07:00:06
问题 How can I read N int s from the input, and stop reading when I find \n ? Also, how can I add them to an array that I can work with? I'm looking for something like this from C but in python while(scanf("%d%c",&somearray[i],&c)!=EOF){ i++; if (c == '\n'){ break; } } 回答1: In Python 2: lst = map(int, raw_input().split()) raw_input() reads a whole line from the input (stopping at the \n ) as a string. .split() creates a list of strings by splitting the input into words. map(int, ...) creates

Proper/Efficient way to determine size of stdin in C

落花浮王杯 提交于 2020-11-29 03:53:12
问题 Based on my previous question, what would be the proper yet efficient way to determine the size of stdin if stdin is coming from a pipe or a terminal on different systems. I was doing the following, however, based on some comments, it is not the right way, and it might or it might not work on different systems. #include <sys/stat.h> off_t size(FILE *st_in) { struct stat st; if (fstat(fileno(st_in), &st) == 0) return st.st_size; return -1; } 回答1: You can't. Imagine stdin is like a water tap.