-1

This is a sample code:

var1 = float(input('Enter time interval: '))
print(f'OK, time interval is {var1}')
# doing something with above variable

I want to run this python file like this without changing the code if possible:

python file.py 0<'15'

But I get this error:

-bash: 15: No such file or directory
Saeed
  • 3,255
  • 4
  • 17
  • 36

2 Answers2

1

You can provide the input through a pipe:

echo 15 | python file.py

Or, with lesser known syntax, using process substitution, which I'm mentioning because it seems like this is what you were trying to do:

python file.py < <(echo 15)

In both cases, be aware of the shell's quoting rules and add quotes accordingly.

If there are multiple lines, a bash heredoc might be easier:

python file.py <<EOF
line1
line2
line3
EOF
Thomas
  • 174,939
  • 50
  • 355
  • 478
1

You can do a

python file.py <<<15

The <<< redirection takes the string to its right and feeds it to the program as standard input.

user1934428
  • 19,864
  • 7
  • 42
  • 87