stdin

ksh: how to probe stdin?

非 Y 不嫁゛ 提交于 2020-01-01 06:15:31
问题 I want my ksh script to have different behaviors depending on whether there is something incoming through stdin or not: (1) cat file.txt | ./script.ksh (then do "cat <&0 >./tmp.dat" and process tmp.dat) vs. (2) ./script.ksh (then process $1 which must be a readable regular file) Checking for stdin to see if it is a terminal[ -t 0 ] is not helpful, because my script is called from an other script. Doing "cat <&0 >./tmp.dat" to check tmp.dat's size hangs up waiting for an EOF from stdin if

docker-compose up and user inputs on stdin

旧时模样 提交于 2020-01-01 05:32:22
问题 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) .

C# Process Standard Input

雨燕双飞 提交于 2019-12-31 04:18:26
问题 I am currently trying to disconnect from a network folder through the command line and am using the following code: System.Diagnostics.Process process2 = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C NET USE F: /delete"; startInfo.RedirectStandardError = true; startInfo

How do I write a testing function for another function that uses stdin input?

夙愿已清 提交于 2019-12-31 01:48:07
问题 I have the following functions as part of a college assignment: int readMenuOption() { /* local declarations */ char option[2]; /* read in 1 char from stdin plus 1 char for string termination character */ readStdin(1 + 1, option); return (int)option[0] <= ASCII_OFFSET ? 0 : (int)option[0] - ASCII_OFFSET; } int readStdin(int limit, char *buffer) { char c; int i = 0; int read = FALSE; while ((c = fgetc(stdin)) != '\n') { /* if the input string buffer has already reached it maximum limit, then

Windows equivalent to “/dev/stdin”?

会有一股神秘感。 提交于 2019-12-30 08:14:45
问题 I have Python code talking to a C++ library which only takes filenames. I want it to read from stdin. On Unix machines I can use "/dev/stdin". I thought I could use the special "CON" device on Windows, but that's more like /dev/tty in that "echo something | my_program" does not work. Supporting pipes under Windows isn't essential, but now I'm curious. Is there something like the filename "/dev/stdin" for that OS? 回答1: To the best of my knowledge there is no equivalent of /dev/stdin. However,

Windows equivalent to “/dev/stdin”?

冷暖自知 提交于 2019-12-30 08:14:23
问题 I have Python code talking to a C++ library which only takes filenames. I want it to read from stdin. On Unix machines I can use "/dev/stdin". I thought I could use the special "CON" device on Windows, but that's more like /dev/tty in that "echo something | my_program" does not work. Supporting pipes under Windows isn't essential, but now I'm curious. Is there something like the filename "/dev/stdin" for that OS? 回答1: To the best of my knowledge there is no equivalent of /dev/stdin. However,

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

冷暖自知 提交于 2019-12-30 07:58:09
问题 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. 回答1: Yes. echo "yesterday" | xargs date +"%d %m %Y" -d 回答2: date -f tells it to do the same thing as -d except for every line in a file... you

Problem with scanf and fgets

我与影子孤独终老i 提交于 2019-12-30 07:20:28
问题 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

How to pipe InputStream to ProcessBuilder

假装没事ソ 提交于 2019-12-30 04:37:25
问题 Please move down to the 2nd update. I didn't want to change the previous context of this question. I'm using wkhtmltoimage from a Java app. The standard way of using it is - path-to-exe http://url.com/ image.png . According to their docs, if we write a - instead of an input URL, the input shifts to STDIN. I'm starting the process using ProcessBuilder - ProcessBuilder pb = new ProcessBuilder(exe_path, " - ", image_save_path); Process process = pb.start(); Now I'm unable to figure out how to

Fastest stdin/out IO in python 3?

别说谁变了你拦得住时间么 提交于 2019-12-30 03:59:05
问题 I've been solving a few problems on SPOJ.pl using python 3.1.2 and some peoples fast result on simple problems makes me wonder if there is a faster way to handle input and output. I've tried using input() print() and sys.stdin.readline() sys.stdout.write() or rather for line in sys.stdin: #Handle input sys.stdout.write(output) to process each line. I've also tried to collect all output in lists and print all at once when everything is processed. But all of these produce similar execution