stdin

PowerShell's pipe adds linefeed

邮差的信 提交于 2019-12-03 16:34:48
问题 I'm trying to pipe a string into a program's STDIN without any trailing linefeeds (unless that string itself actually ends in a linefeed). I tried googling around, but I only found people trying to print to the console without a trailing linefeed, in which case Write-Host takes a parameter -NoNewLine . However, to pipe it on to another program, I need Write-Output or similar which doesn't have such a parameter. Now it seems like Write-Output isn't even the problem: Z:\> (Write-Output "abc")

Passing data between Python and C# without writing a file

你说的曾经没有我的故事 提交于 2019-12-03 16:20:42
I would like to pass binary information between Python and C#. I would assume that you can open a standard in/out channel and read and write to that like a file, but there are a lot of moving parts, and I don't know C# too well. I want to do this sort of thing, but without writing a file. # python code with open(DATA_PIPE_FILE_PATH, 'wb') as fid: fid.write(blob) subprocess.Popen(C_SHARP_EXECUTABLE_FILE_PATH) with open(DATA_PIPE_FILE_PATH, 'rb') as fid: 'Do stuff with the data' // C# code static int Main(string[] args){ byte[] binaryData = File.ReadAllBytes(DataPipeFilePath); byte[] outputData;

docker-compose up and user inputs on stdin

情到浓时终转凉″ 提交于 2019-12-03 16:04:28
Can someone explain (and maybe give a workaround) for the following behavior of docker-compose ? Given the following files : Dockerfile FROM alpine:3.8 COPY ./entrypoint.sh /entrypoint.sh ENTRYPOINT [ "/entrypoint.sh" ] entrypoint.sh #!/bin/sh until [ ! -z "$PLOP" ]; do echo -n 'enter value here: ' read PLOP done echo "Good ... PLOP is $PLOP" exit 1 docker-compose.yml version: '3.7' services: plop: tty: true stdin_open: true image: webofmars/plop:latest The output will be the following: 1) ./entrypoint.sh docker-stdin> ./entrypoint.sh enter value here: CASE1 Good ... PLOP is CASE1 Which seems

how use EOF stdin in C

大憨熊 提交于 2019-12-03 16:00:53
I need to input coordinates into an array until EOF is encountered, but something is wrong in my code. I used ctrl+Z, ctrl+D int main() { int x[1000],y[1000]; int n=0,nr=0,a,b,i; printf("Enter the coordinates:\n"); while(scanf ( "%d %d ", &a, &b) == 2) { x[n]=a; y[n]=b; n++; } if (!feof(stdin)) { printf("Wrong\n"); } else { for(i=0;i<n;i++) printf("%d %d\n", x[i], y[i]); } return 0; } I suggest using while(!feof(stdin) && scanf ( "%d %d ", &a, &b) == 2) and actually it is better to test feof after (not before!) some input operation, so: while (scanf("%d %d ", &a, &b) == 2 && !feof(stdin)) BTW,

How to create non-blocking continuous reading from `stdin`?

[亡魂溺海] 提交于 2019-12-03 14:38:10
问题 I have a single process, which has been created like this: p = subprocess.Popen(args = './myapp', stdin = subprocess.PIPE, stdout = subprocess.PIPE, universal_newlines=True) Later on, I'm trying to write to p 's stdin : p.stdin.write('my message\n') The myapp process has the following setup: q = queue.Queue() def get_input(): for line in iter(sys.stdin.readline, ''): q.put(line) sys.stdin.close() threading.Thread(name = 'input-getter', target = get_input).start() And it is trying to read new

Faster way to write image to Process.StandardInput.BaseStream

微笑、不失礼 提交于 2019-12-03 13:42:12
问题 Im trying to send a lot of desktop captured images to an encoders (FFmpeg) stdin. The following code example works. the CaptureScreen() function provides an image in 5-10 ms. If I save the image in a MemoryStream it takes almost no time. But I can only save 1 image every 45 ms to proc.StandardInput.BaseStream. public void Start(string bitrate, string buffer, string fps, string rtmp, string resolution, string preset) { proc.StartInfo.FileName = myPath + "\\ffmpeg.exe"; proc.StartInfo.Arguments

Nonblocking Get Character

雨燕双飞 提交于 2019-12-03 12:11:15
Platform: Linux 3.2.0 x86 (Debian 7) Compiler: GCC 4.7.2 (Debian 4.7.2-5) I am writing a function that reads a single character from stdin if a character is already present in stdin. If stdin is empty the function is suppose to do nothing and return -1. I googled nonblocking input and was pointed to poll() or select() . First I tried to use select() but I could not get it to work so I tried poll() and reached the same conclusion. I am not sure what these functions do exactly but from what I understand of poll()'s documentation if I call it like so: struct pollfd pollfds; pollfds = STDIN_FILENO

How to read stdin when no arguments are passed?

ⅰ亾dé卋堺 提交于 2019-12-03 12:05:00
Script doesn't work when I want to use standard input when there are no arguments (files) passed. Is there any way how to use stdin instead of a file in this code? I tried this: if [ ! -n $1 ] # check if argument exists then $1=$(</dev/stdin) # if not use stdin as an argument fi var="$1" while read line do ... # find the longest line done <"$var" pilcrow Just substitute bash's specially interpreted /dev/stdin as the filename: VAR=$1 while read blah; do ... done < "${VAR:-/dev/stdin}" (Note that bash will actually use that special file /dev/stdin if built for an OS that offers it , but since

How can I check (peek) STDIN for piped data in Perl without using select?

拜拜、爱过 提交于 2019-12-03 12:04:43
I'm trying to handle the possibility that no arguments and no piped data is passed to a Perl script. I'm assuming that if there are no arguments then input is being piped via STDIN. However if the user provides no arguments and does not pipe anything to the script, it will try to get keyboard input. My objective is to provide an error message instead. Unfortunately, select() is not portable to some non-POSIX systems. Is there another way to do this with maximum portability? Perl comes with the -t file-test operator, which tells you if a particular filehandle is open to a TTY. So, you should be

Reading long int using scanf

前提是你 提交于 2019-12-03 11:27:16
To read an int using scanf we use: scanf("%d", &i); What if i is a long not int ?? Note: when using %d with long it gives me an irritating warning.. Just use long l; scanf("%ld", &l); it gives me an irritating warning.. That warning is quite right. This is begging for stack corruption. For gods sake: long n; scanf( "%ld", & n ); scanf("%ld", &i); You can also use "%Ld" for a long long (and depending on your compiler, sometimes also "%lld" ). Take a look at the Conversions section of the scanf man page for more. (Just Google it if your system doesn't have manpages). Each conversion specifier