stdin

Read file without fopen() (C language)

自作多情 提交于 2019-12-01 18:48:20
I am working on a school project in which we have to do some operations (select, min, max) on a table saved in .txt file. The problem is that we can't use common functions such as fopen, fscanf, fclose. The program will be launched from command line like this: .\project.exe select parameters <table.txt Do you have some ideas how to get content of the .txt file to stdin without using fopen? Thanks. You do not need to open the file - the operating environment will do it for you. When your program is called with <table.txt , your standard input is switched to read from that file instead of the

Redirect STDIN in bash?

醉酒当歌 提交于 2019-12-01 18:08:01
For an example i would like to login to mysql with a password. i KNOW i can use -pmypass but i want to learn how do i redirect stdin in bash. So my test is mysql -u limited_user -p <text to redirect into stdin when it prompts for my pass> I seen < filename before but i dont want to store the data in a file. I tried & and &- but had no luck. I am not sure what &- does. Matthew Flaschen Normally, it's just: echo password|command But many programs, including MySQL, that read passwords don't actually read from stdin. Rather, they interact with the terminal directly. See Trick an application into

Redirect STDIN in bash?

ぃ、小莉子 提交于 2019-12-01 17:48:16
问题 For an example i would like to login to mysql with a password. i KNOW i can use -pmypass but i want to learn how do i redirect stdin in bash. So my test is mysql -u limited_user -p <text to redirect into stdin when it prompts for my pass> I seen < filename before but i dont want to store the data in a file. I tried & and &- but had no luck. I am not sure what &- does. 回答1: Normally, it's just: echo password|command But many programs, including MySQL, that read passwords don't actually read

reading stdin multiple times in bash

落花浮王杯 提交于 2019-12-01 16:38:18
I'm trying to read from stdin multiple times in a shell script, with no luck. The intention is to read a list of files first (which are read from the stdin pipe), and then read twice more to get two strings interactively. (What I'm trying to do is read a list of files to attach in an email, then the subject and finally the email body). So far I have this: photos=($(< /dev/stdin)) echo "Enter message subject" subject=$(< /dev/stdin) echo "Enter message body" body=$(< /dev/stdin) (plus error checking code that I omit for succintness) However, this gets an empty subject and body presumably

How to read a single character from input as u8?

依然范特西╮ 提交于 2019-12-01 15:32:55
问题 I am currently building a simple interpreter for this language for practice. The only problem left to overcome is reading a single byte as a character from user input. I have the following code so far, but I need a way to turn the String that the second lines makes into a u8 or another integer that I can cast: let input = String::new() let string = std::io::stdin().read_line(&mut input).ok().expect("Failed to read line"); let bytes = string.chars().nth(0) // Turn this to byte? The value in

how to give subprocess a password and get stdout at the same time

南楼画角 提交于 2019-12-01 13:16:58
I'm trying to check for the existence of an executable on a remote machine, then run said executable. To do so I'm using subprocess to run ssh <host> ls <file> , and if that's successful, run ssh <host> <file> . ssh asks for a password, of course, and I'd like to provide that automatically. Also, I'd like to get the returncode from ls, and stdout and stderr from running the command. So I know the communicate() method is needed, to avoid deadlocks, but I can't get the password to be recognized by Popen(stdin) . Also I'm using Python 2.4.3, and stuck on that version. Here's the code I've got so

calling bash from python

懵懂的女人 提交于 2019-12-01 12:59:32
I have a python script which calles a bash script. The bash script compiles several modules and I would like to seethe result of the compilation printed on screen while running. Most important, anyway, is that the bash script requires a run time quite some few input from the user. How can I make my python script give stdin/stdout to the bash script? For the moment I am using (_stat, _resl) = commands.getstatusoutput("./myBashScript") but in this way the user is not promped of anything while the bash is running... Cheers If you use subprocess (as you should!) and don't specify stdin/stdout

how to give subprocess a password and get stdout at the same time

旧时模样 提交于 2019-12-01 12:29:58
问题 I'm trying to check for the existence of an executable on a remote machine, then run said executable. To do so I'm using subprocess to run ssh <host> ls <file> , and if that's successful, run ssh <host> <file> . ssh asks for a password, of course, and I'd like to provide that automatically. Also, I'd like to get the returncode from ls, and stdout and stderr from running the command. So I know the communicate() method is needed, to avoid deadlocks, but I can't get the password to be recognized

Capturing a variable length string from the command-line in C

狂风中的少年 提交于 2019-12-01 12:28:30
I've looked everywhere for an answer to my question, but I have yet to find a solid answer to my problem. I'm currently in the process of writing a program in C, specifically targeting the UNIX command line (I'm using Linux as my development environment, but I'd like for this program to be as portable as possible). Right now, I have a basic shell that prompts for user input. The user will then enter in a command, and that command will be processed accordingly. Here is the code that I have so far: /* Main.c */ int main(int argc, char **argv) { while (TRUE) { display_prompt(); get_command(); }

Capturing a variable length string from the command-line in C

人盡茶涼 提交于 2019-12-01 09:47:32
问题 I've looked everywhere for an answer to my question, but I have yet to find a solid answer to my problem. I'm currently in the process of writing a program in C, specifically targeting the UNIX command line (I'm using Linux as my development environment, but I'd like for this program to be as portable as possible). Right now, I have a basic shell that prompts for user input. The user will then enter in a command, and that command will be processed accordingly. Here is the code that I have so