stdin

How do you pipe input and output to and from an interactive shell?

拥有回忆 提交于 2021-02-08 03:33:22
问题 I am trying to build an application that enables the user to interact with a command-line interactive shell, like IRB or Python. This means that I need to pipe user input into the shell and the shell's output back to the user. I was hoping this was going to be as easy as piping STDIN, STDOUT, and STDERR, but most shells seem to respond differently to STDIN input as opposed to direct keyboard input. For example, here is what happens when I pipe STDIN into python : $ python 1> py.out 2> py.err

How do you pipe input and output to and from an interactive shell?

别说谁变了你拦得住时间么 提交于 2021-02-08 03:31:13
问题 I am trying to build an application that enables the user to interact with a command-line interactive shell, like IRB or Python. This means that I need to pipe user input into the shell and the shell's output back to the user. I was hoping this was going to be as easy as piping STDIN, STDOUT, and STDERR, but most shells seem to respond differently to STDIN input as opposed to direct keyboard input. For example, here is what happens when I pipe STDIN into python : $ python 1> py.out 2> py.err

Linux NASM detect EOF

蹲街弑〆低调 提交于 2021-02-07 13:17:27
问题 I'm trying to learn the basics asm on linux and I can't find a very good reference. The NASM docs seem to assume you already know masm... I found no examples in the documentation of the cmp (outside the Intel instruction reference). I'd written a program that reads a single byte from stdin and writes it to stdout. Below is my modification to try to detect EOF on stdin and exit when EOF is reached. The issue is it never exits. I just keeps printing the last char read from stdin. The issue is

Linux NASM detect EOF

老子叫甜甜 提交于 2021-02-07 13:12:55
问题 I'm trying to learn the basics asm on linux and I can't find a very good reference. The NASM docs seem to assume you already know masm... I found no examples in the documentation of the cmp (outside the Intel instruction reference). I'd written a program that reads a single byte from stdin and writes it to stdout. Below is my modification to try to detect EOF on stdin and exit when EOF is reached. The issue is it never exits. I just keeps printing the last char read from stdin. The issue is

python asyncio gets deadlock if multiple stdin input is needed

不打扰是莪最后的温柔 提交于 2021-02-07 05:27:19
问题 I wrote a command-line tool to execute git pull for multiple git repos using python asyncio. It works fine if all repos have ssh password-less login setup. It also works fine if only 1 repo needs password input. When multiple repos require password input, it seems to get deadlock. My implementation is very simple. The main logic is utils.exec_async_tasks( utils.run_async(path, cmds) for path in repos.values()) where run_async creates and awaits a subprocess call, and exec_async_tasks runs all

Communicate with C program using stdin/out from Java

為{幸葍}努か 提交于 2021-02-05 11:34:12
问题 I want my Java program to communicate with a C program. This is just a simple example but I can't get it working. The Java program is supposed to run the C program and write to its input stream. The C program should see this and write to stdout in response. Finally, the Java program should read this response from the C program's stdout and print it to the screen. Running the C program from command line I get the desired behaviour. However, when ran from the Java program, it just "hangs" and

How to get a string input from stdin that has leading white space in C?

送分小仙女□ 提交于 2021-02-05 05:51:06
问题 Need a solution to get input string start with spaces? I know a method to include space in input scanf("%[^\n]s", s); But its working only for space between words. I need a solution for string starts with spaces. And I also need the starting spaces in the variable 回答1: To get a line of user input, use fgets() . #define S_MAX_LENGTH char s[S_MAX_LENGTH + 2]; if (fgets(s, sizeof s, stdin)) { s[strcspn(s, "\n")] = '\0'; // Should code want to lop off a potential trailing \n .... Do not use scanf

Type conversion of a string read from stdin to int is giving me a 0

半世苍凉 提交于 2021-01-29 08:25:24
问题 Code: reader := bufio.NewReader(os.Stdin) fmt.Print("Enter a number") input,_ := reader.ReadString('\n') fmt.Printf("Type of the entered value is %T\n",input) fmt.Println(input) out,_ := strconv.Atoi(input) fmt.Printf("Type now is: %T\n", out) fmt.Printf("Value now is %d\n",out) fmt.Println(out) Complete beginner to Golang. I was trying to solve one of the problems from r/dailyprogrammer. I took the snippet to read the input from SO, as well as the strconv.Atoi function. The examples for this

C - how to poll() input without buffering?

天涯浪子 提交于 2021-01-29 07:54:12
问题 I am trying to detect any character typed to stdin (without a newline character). I tried : setvbuf(stdin, NULL, _IONBF); //This returns 0 struct pollfd pfd = {STDIN_FILENO, POLLIN}; while (!poll(pfd, 1, ms)) { /* do some thing, e.g. printf("n\n"); */ } It appears not stop printing when I typed q , but did stop after I hit enter . The system I am working on is arch-linux, compiler is gcc. 回答1: The q is being held up in the kernel's TTY layer driver/buffer because it is in "cooked" mode. In

How to read a file passed through stdin in C

邮差的信 提交于 2021-01-29 06:50:14
问题 I want to pass a text file to a C program like this ./program < text.txt . I found out on SO that arguments passed like that dont appear in argv[] but rather in stdin . How can I open the file in stdin and read it? 回答1: You can directly read the data without having to open the file. stdin is already open. Without special checks your program doesn't know if it is a file or input from a terminal or from a pipe. You can access stdin by its file descriptor 0 using read or use functions from stdio