stdin

Can I pass a string as stdin to a system call from vim?

◇◆丶佛笑我妖孽 提交于 2019-12-22 09:49:24
问题 I want to run a system command from vim ( :help :! ), and I want to pass the contents of a string variable as stdin for that command. I already know I can pass lines from the current buffer as stdin (see :help :w_c ). But I don't want to modify the current buffer, and I don't want to make a new buffer. I know I can write the string to a temporary file, then pipe that file as input and delete it. Right now, that's the best solution I know for my application. But it would be cleaner to avoid

python cat (echo) equivalent for stdin

百般思念 提交于 2019-12-22 09:28:32
问题 I thought this program will echo my console input line by line: import os, sys for line in sys.stdin: print line Unfortunately it waits for EOF ( Ctrl + D ) and then it produces output. How should I modify my program to get output line by line? 回答1: Python 2.x: for line in iter(sys.stdin.readline, ''): print line, Python 3.x: for line in iter(sys.stdin.readline, ''): print(line, end='') See the documentation on iter() with two arguments, it actually has reading from a file like this as one of

Redirect stdout of two processes to another process's stdin in Linux C

倖福魔咒の 提交于 2019-12-22 08:41:11
问题 I'm running into problem about redirect stdout of multi process. Assuming I have process A, I use fork() in A and then I get process A and B. And I use fork() in B, finally I get process A, B and C. Both B and C are implementing other program by exec(). Now, I try to redirect the stdout of A and B to stdin of C with two pipes. #include<unistd.h> #include<stdio.h> #include<sty/types.h> int main() { int AtoC [2]; pipe(AtoC); int fd1,fd2; fd1=fork(); if(fd1>0) { /***In process A, I do the

How to test stdin for a CLI using rspec

旧巷老猫 提交于 2019-12-22 08:38:27
问题 I'm making a small Ruby program and can't figure out how to write RSpec specs that simulate multiple user command line inputs (the functionality itself works). I think this StackOverflow answer probably covers ground that is closest to where I am, but it's not quite what I need. I am using Thor for the command line interface, but I don't think this is an issue with anything in Thor. The program can read in commands either from a file or the command line, and I've been able to successfully

“Pseudo-terminal will not be allocated because stdin is not a terminal” when running ssh through python without paramiko

ⅰ亾dé卋堺 提交于 2019-12-22 08:09:27
问题 I am running ssh from within Python without the use of an external library like Paramiko. I have my reasons for doing it this way instead of through an external library. Basically I am doing subprocess.Popen("ssh -t bla -- command") I get the following message when doing this: Pseudo-terminal will not be allocated because stdin is not a terminal. The reason I am running it with -t is I want the remote command to terminate when I kill my python script. When I try with -t -t (to force it), I

Create a cmd window and write to it from C# application

丶灬走出姿态 提交于 2019-12-22 07:59:43
问题 I am developing a C# component for Grasshopper for Rhino. As I am running some pretty heavy iterative analysis I would like to output results continuously to a cmd window just to make sure that the analysis is actually running. Here's what I tried: using System.Diagnostics; Result results = new Result(); Process cmd = new Process(); cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.CreateNoWindow = false;

How do i run a program from another program and pass data to it via stdin in c or c++?

安稳与你 提交于 2019-12-22 06:28:15
问题 Say i have an exe, lets say sum.exe. Now say the code for sum.exe is void main () { int a,b; scanf ("%d%d", &a, &b); printf ("%d", a+b); } I wanted to know how i could run this program from another c/c++ program and pass input via stdin like they do in online compiler sites like ideone where i type the code in and provide the stdin data in a textbox and that data is accepted by the program using scanf or cin. Also, i wanted to know if there was any way to read the output of this program from

C: Read from stdin until Enter is pressed twice

情到浓时终转凉″ 提交于 2019-12-22 05:41:44
问题 Consider a simple program. It must take sequences of 5 numbers from stdin and print their sums. It is not stated how many lines of input will be taken, but program must terminate if newline character is taken twice (or Enter is pressed twice). For example, Input: 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3/n /n Output: 5 10 15 #include <stdio.h> int main() { int n1, n2, n3, n4, n5; int sum; while (/*condition*/) { scanf ("%d %d %d %d %d\n", &n1, &n2, &n3, &n4, &n5); sum = n1 + n2 + n3 + n4 + n5; printf ("

stdin into zip command, how do I specify a file name?

吃可爱长大的小学妹 提交于 2019-12-22 03:06:11
问题 I want to compress the contents of stdin using zip , for instance: echo 'foo bar' | zip > file.zip This works ok, but when unzipping, the uncompressed file name is - I was wondering how I could specify a file name for stdin? 回答1: What you can do is pipe the file in normally, then rename it in the zip echo 'foo bar' | zip > file.zip printf "@ -\n@=filename.txt\n" | zipnote -w file.zip 回答2: echo 'foo bar' | zip -@ /path/to/zipfile.zip should do it while keeping filename integrity 来源: https:/

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

喜夏-厌秋 提交于 2019-12-21 21:37:02
问题 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); }