Friday 15 January 2010

Stdin redirection from Python -


I have a program that can be read by the name of some_binary :

  few_languages ​​< Input   

Where input is usually a file in the disk.

/ Code> Usually a file containing the following content I have this in Python:

  0 0.2 0 0.4 1 0.2 0 0.3 0 0.5 1 0.7   

I do this in Python like this: < Import as pre> np # np # random binary numbers first_column = np.random.random_integers (0,1, (6,)) random number between # 0 and 1 second_column = np .random.random ( (6,))

How can I feed the combination of some_binary to first_column and second_column As I some_binary & lt; , Cwd = None, my_input): retVal = subprocess.Popen (cmd, shell = true, stdout = subprocess.PIPE, stdin = my_input, cwd = cwd); RetVal = retVal.stdout.read (). Strip ('\ n'); Retval;

But I'm not sure I'm going in the right direction.

Yes, you are going in the right direction.

You can use Python subprocess.check_output () function which is a feature wrapper around the subprocess. Popen () . Popen needs more infrastructure

something like

when something happens

< / P>

<> Output = Subprances Checkout ([CMD], stdin = my_input)

should work in your case.

No comments:

Post a Comment