stdin

Using standard io stream:stdin and stdout in a matlab exe

荒凉一梦 提交于 2019-12-01 04:08:32
问题 Question I want it to 'listen' to the standard input stream in a running (compiled) Matlab executable. This is how I believe it is done in c or a similar language: #include stdio.h fgets(line, 256, stdin) Or more elaborately, it it can be used as such: if (!fgets(line, 256, stdin)) return; if (line[0] == '\n') continue; sscanf(line, "%s", command); Answer For completeness I will leave the background and notes intact, but with the help of Amro and EitanT I have managed to work it out.

Using read -p in a bash script that was executed from pipe

和自甴很熟 提交于 2019-12-01 03:26:03
问题 I apologize in advance - I don't fully understand the ideas behind what I'm asking well enough to understand why it's not working ( I don't know what I need to learn ). I searched stack exchange for answers first - I found some information that seemed possibly relevant, but didn't explain the concepts well enough that I understood how to build a working solution. I've been scouring google but haven't found any information that describes exactly what's going on in such a way that I understand.

Which is the better way to pass data into Python Unittest Redirected STDIN or Pickle?

自闭症网瘾萝莉.ら 提交于 2019-12-01 03:21:48
问题 Short Question What is the best way to get data into a Python unittest case ? Background My project is using Python's unittest module as an automated way execute a series of tests that will need to run on many of the same type of boards. So far this is a good fit to what the unittest module was designed for; the twist is that each test case needs to know run specific information to store in a Django database. The data that needs to be passed in includes a serial number, who tested the board,

How do I read a single String from standard input?

限于喜欢 提交于 2019-12-01 03:10:06
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. Here's the code you need to do what you are trying (no comments on if it is a good way to go about it: use std::io::{self, BufRead}; fn main() { let stdin = io::stdin(); let line = stdin.lock() .lines()

Pipe string to GNU Date for conversion - how to make it read from stdin?

限于喜欢 提交于 2019-12-01 02:34:30
GNU Date lets you convert date strings like so: $ date +"%d %m %Y" -d "yesterday" 04 01 2012 Is it possible to pipe a date string to it for conversion? I've tried the obvious -d - like so: $ echo "yesterday" | date +"%d %m %Y" -d - but it prints today's date instead of yesterdays. Is it possible to pipe values to it or doesn't it support that? Thanks. Yes. echo "yesterday" | xargs date +"%d %m %Y" -d date -f tells it to do the same thing as -d except for every line in a file... you can set the filename to - to make it read from standard input. echo "yesterday" | date +"%d %m %Y" -f - You can

Why do i have to input EOF 3 times when using fgets?

大憨熊 提交于 2019-12-01 01:29:48
So basically I want to copy everything i write to stdin (including newline char) to string for hash purposes. I managed to accomplish that and made small code to represent my problem. #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUFFERSIZE 10000 int main() { char *myStr = calloc(1,1); char buffer[BUFFERSIZE]; while( fgets(buffer, BUFFERSIZE , stdin) != NULL ){ myStr = realloc(myStr, strlen(myStr)+1+strlen(buffer) ); strcat( myStr, buffer ); } printf("\n%s\n",myStr); } everything works when I enter some text then press ENTER and after I call EOF. But when I start program

Problem with scanf and fgets

我怕爱的太早我们不能终老 提交于 2019-12-01 00:17:13
This is for a homework assignment to sort some given strings. I'm prompting the user for the number of strings they'd like to sort with scanf , allocating an array based on that number, and then getting the strings themselves with fgets . Everything works fine if the number of strings is hardcoded, but the addition of scanf to let the user decide screws things up. Here's the code: #include <assert.h> #include <stdio.h> #include <stdlib.h> #define LENGTH 20 // Maximum string length. int main(void) { int index, numStrings = 0; char **stringArray; printf("Input the number of strings that you'd

formatting strings for stdin.write() in python 3.x

别来无恙 提交于 2019-11-30 23:23:35
问题 I'm having a problem where I get errors when I try to execute this code with python 3.2.2 working_file = subprocess.Popen(["/pyRoot/iAmAProgram"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) working_file.stdin.write('message') I understand that python 3 changed the way it handles strings but I dont understand how to format the 'message'. Does anyone know how I'd change this code to be valid? many thanks jon update: heres the error message i get Traceback (most

C select() timeout STDIN single char (no ENTER)

假如想象 提交于 2019-11-30 22:52:19
I want to be able to use select() to work with entering a single char (no ENTER) from STDIN. So, when a user press a single key, select() should return immediately, not waiting for the user to hit ENTER. int main(void) { fd_set rfds; struct timeval tv; int retval; /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&rfds); FD_SET(0, &rfds); /* Wait up to 2 seconds. */ tv.tv_sec = 2; tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); if (retval == -1) perror("select()"); else if (retval) printf("Data is available now.\n"); else printf("No data within five seconds.\n"); exit(EXIT

Ignore backspace key from stdin

和自甴很熟 提交于 2019-11-30 21:59: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? 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(oldtio)); newtio.c_lflag = ICANON; newtio.c_cc[VERASE] = 0; /* turn off del */ tcflush(fd, TCIFLUSH); tcsetattr