stdin

Start runas as subprocess and write password to stdin?

拜拜、爱过 提交于 2019-12-21 21:32:10
问题 I am trying to write a C# program that is supposed to call the runas tool from windows and input the password automatically. What I tried: Process runas = new Process(); runas.StartInfo.FileName = "runas"; runas.StartInfo.UseShellExecute = false; runas.StartInfo.RedirectStandardInput = true; runas.StartInfo.Arguments = "\"/user:domain\\username\" \"cmd.exe\""; runas.Start(); StreamWriter stream = runas.StandardInput; stream.WriteLine("our super secret password"); stream.Flush(); stream.Close(

Sending strings between to Python Scripts using subprocess PIPEs

岁酱吖の 提交于 2019-12-21 20:16:10
问题 I want to open a Python script using subprocess in my main python program. I want these two programs to be able to chat with one another as they are both running so I can monitor the activity in the slave script, i.e. I need them to send strings between each other. The main program will have a function similar to this that will communicate with and monitor the slave script: Script 1 import subprocess import pickle import sys import time import os def communicate(clock_speed, channel_number,

How do I push a string to stdin? Provide input via stdin on startup, then read stdin input interactively

感情迁移 提交于 2019-12-21 20:08:33
问题 Is there a way to "push" a string to the stdin stream of a program when calling it? So that we would have the effect of echo "something" | ./my_program but instead of reading EOF after "something" , my_program would read its further input from the original stdin (e.g., the keyboard). Example: Say we want to start a bash shell, but the first thing we would like to do inside it is to call date . echo date | bash would not do the job, as the shell would terminate after running date . 回答1: This

How to write to stdin of execved process?

╄→尐↘猪︶ㄣ 提交于 2019-12-21 15:15:08
问题 I'm trying to execve a process that reads from stdin. I want to prepare stdin with some data so it can execute successfully. How can I do that? 回答1: You will need to fork the execve call into a child process and then create a pipe from the parent process to the child's stdin. Take a look at this link for a detailed example on how to use pipes: http://tldp.org/LDP/lpg/node11.html 来源: https://stackoverflow.com/questions/12611457/how-to-write-to-stdin-of-execved-process

How to evaluate powershell script inputed from stdin

喜夏-厌秋 提交于 2019-12-21 12:21:23
问题 I want to evaluate the content from StdIn in Powershell, like this: echo "echo 12;" | powershell -noprofile -noninteractive -command "$input | iex" Output: echo 12; Unfortunately, $input is not a String, but a System.Management.Automation.Internal.ObjectReader , which make iex not working as expected... since this one is working correctly: powershell -noprofile -noninteractive -command "$command = \"echo 12;\"; $command | iex" Output: 12 回答1: The following would work: Use a scriptblock: echo

Python : Postfix stdin

落爺英雄遲暮 提交于 2019-12-21 12:08:44
问题 I want to make postfix send all emails to a python script that will scan the emails. However, how do I pipe the output from postfix to python ? What is the stdin for Python ? Can you give a code example ? 回答1: To push mail from postfix to a python script, add a line like this to your postfix alias file: # send to emailname@example.com emailname: "|/path/to/script.py" The python email.FeedParser module can construct an object representing a MIME email message from stdin, by doing something

Detect if stdin is a tty device (terminal) or pipe in PHP?

风流意气都作罢 提交于 2019-12-21 07:28:21
问题 I wrote a php script. I want it show help message when called with standard input connected to a tty device (terminal) before reading and executing interactively, but dont show when called with a file or stream from pipe as standard input. Is there a way to detect this from PHP? 回答1: Use posix_isatty. This function accepts both a file descriptor (an integer) and a PHP stream. If it receives a PHP stream, it automatically attempts to cast it in order to obtain a file descriptor and use it

How to pass Rscript -e a multiline string?

戏子无情 提交于 2019-12-21 07:00:08
问题 Is there a way to provide the code to Rscript -e in multiple lines? This is possible in vanilla R R --vanilla <<code a <- "hello\n" cat(a) code But using Rscript I get two different things depending on the R version. # R 3.0.2 gives two ignores Rscript -e ' quote> a <- 3+3 quote> cat(a, "\n") quote> ' # ARGUMENT 'cat(a,~+~"' __ignored__ # ARGUMENT '")' __ignored__ Rscript -e 'a <- 3+3;cat(a, "\n")' # ARGUMENT '")' __ignored__ # R 2.15.3 gives an ignore for the multiline, but it works with

C| how to check if my input buffer(stdin) is empty?

て烟熏妆下的殇ゞ 提交于 2019-12-21 06:48:30
问题 I want to know how to check if my input buffer(perhaps its called stdin) is empty or not. i dont want the program to stop if the buffer is empty, and i dont want the input to necessarily end with '\n', therefore just using scanf is not enough. i tried searching on google and on this website but no answer was enough. i tried using feof(stdin) like this: int main() { char c,x; int num; scanf("%c",&c); scanf("%c",&x); num=feof(stdin); printf("%d",num); } but all it did was printing 0 no matter

If fclose(0) is called, does this close stdin?

∥☆過路亽.° 提交于 2019-12-21 03:42:54
问题 If fclose(0) is called, does this close stdin? The reason why I'm asking this is that for some reason, stdin is being closed in my application and I cannot figure out why. I checked for fclose (stdin) and this is not in the application and so I was wondering if fclose(0) could cause undefined behaviour such as closing stdin? If not, what are other ways that stdin could be erroneously closed? 回答1: The signature of fclose is this: int fclose ( FILE * stream ); That means, fclose expects a