1

I am dealing with a large data set and it takes some days to run, therefore I use nohup to run my script in terminal. This time I need to first get a raw_input from terminal then by nohup, my codes starts running. Any suggestion how I can do that?

so first I need to get input from terminal like this

$ python myprogram.py 
enter_input: SOMETHING

then the process should be like this:

$nohup python myprogram.py &

But I want to do this in one step via terminal. I hope my explanation is clear :)

masti
  • 157
  • 1
  • 5
  • 11
  • 2
    you explanation wasn't clear. i think you want sys.argv though. but i think you can do it with something like `nohup python myprogram.py raw_input` then access it with `sys.argv[1]` – Mahdi Yusuf Nov 04 '11 at 15:31
  • 1
    yes, it works by introducing sys.argv[1] in the code and in terminal I enter: $ nohup python myprogram.py SOMTHING & By this SOMETHING will be input... – masti Nov 04 '11 at 15:42

3 Answers3

2

Here's one more option, in case you want to stick with the user-friendly nature of the input box. I did something like this because I needed a password field, and didn't want the user to have to display their password in the terminal. As described here, you can create a small wrapper shell script with input boxes (with or without the -s option to hide), and then pass those variables via the sys.argv solution above. Something like this, saved in an executable my_program.sh:

echo enter_input:
read input

echo enter_password:
read -s password

nohup python myprogram.py $username $password &

Now, running ./my_program.sh will behave exactly like your original python my_program.py

Paul Fornia
  • 452
  • 3
  • 9
1

You could make your process fork to the background after reading the input. The by far easier variant, though, is to start your process inside tmux or GNU screen.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
1

I think you shouldn't your program have read input from stdin, but give it data via its command line.

So instead of

startdata = raw_input('enter_input:')

you do

import sys
startdata = sys.argv[1]

and you start your program with

$ nohup python myprogram.py SOMETHING &

and all works the way you want - if I get you right.

glglgl
  • 89,107
  • 13
  • 149
  • 217