stdin

Using files as stdin and stdout for subprocess

你离开我真会死。 提交于 2019-12-20 10:24:28
问题 How do I replicate the following batch command using python subprocess module? myprogram < myinput.in > myoutput.out In other words, how do I run myprogram using the contents of myinput.in as the standard input and myoutput.out as standard output? 回答1: The following should work: myinput = open('myinput.in') myoutput = open('myoutput.out', 'w') p = subprocess.Popen('myprogram.exe', stdin=myinput, stdout=myoutput) p.wait() myoutput.flush() 来源: https://stackoverflow.com/questions/15167603/using

Python - HTTP post from stdin [closed]

只愿长相守 提交于 2019-12-20 07:40:36
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am getting data in this format every second or so from a bash command 'ibeacon_scan" ibeacon scan -b | stdin.py Output: ibeacon scan... 3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6 1 4 -71 -69 3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6 6 2 -71 -63 3F234454-CFD-4A0FF-ADF2-F4911BA9FFA6 1 4 -71 -69 3F234454-CFD-4A0FF-ADF2

Is there a way to use locked standard input and output in a constructor to live as long as the struct you're constructing?

妖精的绣舞 提交于 2019-12-20 05:36:48
问题 I'm building a PromptSet that can ask a series of questions in a row. For testing reasons, it allows you to pass a reader and writer instead of using stdin & stdout directly. Because stdin and stdout are the common use case, I would like to create a default "constructor" that allows the user to produce a PromptSet<StdinLock, StdoutLock> without needing any parameters. Here's the code so far: use std::io::{self, BufRead, StdinLock, StdoutLock, Write}; pub struct PromptSet<R, W> where R:

Multiple input with proc_open()

北战南征 提交于 2019-12-20 03:43:09
问题 I'm currently working on an online program. I'm writing a php script that executes a command in the command line with proc_open() (under Linux Ubuntu). This is my code so far: <?php $cmd = "./power"; $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"), ); $process = proc_open($cmd, $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], "4"); fwrite($pipes[0], "5"); fclose($pipes[0]); while($pdf_content = fgets($pipes[1])) { echo

How to get the name of a file acting as stdin/stdout?

浪子不回头ぞ 提交于 2019-12-20 02:47:26
问题 I'm having the following problem. I want to write a program in Fortran90 which I want to be able to call like this: ./program.x < main.in > main.out Additionally to "main.out" (whose name I can set when calling the program), secondary outputs have to be written and I wanted them to have a similar name to either "main.in" or "main.out" (they are not actually called "main"); however, when I use: INQUIRE(UNIT=5,NAME=sInputName) The content of sInputName becomes "Stdin" instead of the name of the

reading stdin multiple times in bash

流过昼夜 提交于 2019-12-19 17:05:23
问题 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

reading stdin multiple times in bash

风格不统一 提交于 2019-12-19 17:04:45
问题 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

Communicate with external C program with Java using stdin and stdout

心不动则不痛 提交于 2019-12-19 10:23:05
问题 What I'm trying to do is launch the C program executable inside the Java application and allow them to communicate with each other using stdin and stdout. The C program will wait for a command from the java app and echo it back. I've tested the java code with "gnugo --mode gtp" (gnugo with in gtp mode communicates with stdin and stdout) and it works fine but my doesn't work with my C code. Any suggestion would greatly appreciated. C code #include <stdio.h> #include <stdlib.h> #include <string

How to test if STDIN is terminal in batch?

不问归期 提交于 2019-12-19 09:14:10
问题 In shell I can do this: if test -t 0 ; then echo stdin is a tty exit 0 fi How can I do this in batch? 回答1: EDITED - Thank you to all the testers. @echo off timeout 1 2>nul >nul if errorlevel 1 ( echo input redirected ) else ( echo input is console ) The timeout command tries to directly get access to the console, and this will fail if the batch file is executed as myBatchFile.cmd < input.txt echo something | myBatchFile.cmd Tested on Windows XP (timeout from W2003 Resource Kit), 7 and 8.1. 来源

Redirect input and output for cmd.exe

半腔热情 提交于 2019-12-19 09:06:47
问题 I wanna redirect cmd.exe output somewhere, below code works when the command is a line: Process p = new Process() { StartInfo = new ProcessStartInfo("cmd") { UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true, Arguments = String.Format("/c \"{0}\"", command), } }; p.OutputDataReceived += (s, e) => Messagebox.Show(e.Data); p.Start(); p.BeginOutputReadLine(); p.WaitForExit(); But how about a series commands like WriteLine(): p