Python Forum
python command (2 and 3) ignores extra -c arguments - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: python command (2 and 3) ignores extra -c arguments (/thread-20692.html)



python command (2 and 3) ignores extra -c arguments - Skaperen - Aug-25-2019

both the python3 and python2 commands (at least in Ubuntu 18.04) takes (or ignores) an extra -c argument and only executes the first one. it should give an error message about the extras if it is wrong to use them.
Output:
lt2a/forums /home/forums 13> python3 -c "print('foo')" -c "print('bar')" foo lt2a/forums /home/forums 14> python2 -c "print('foo')" -c "print('bar')" foo lt2a/forums /home/forums 15>
i was hoping it would be an easy way to give it another "line" of code to run.


RE: python command (2 and 3) ignores extra -c arguments - ichabod801 - Aug-25-2019

Output:
(C:\Users\Craig\Anaconda2) C:\Users\Craig\Documents\t_games>python -c "print 'foo'; print 'bar'" foo bar



RE: python command (2 and 3) ignores extra -c arguments - Skaperen - Aug-26-2019

i tried it with ; but it would not work with just any code. nested stuff was not working. it works when the string -c gets has real \n.


RE: python command (2 and 3) ignores extra -c arguments - ichabod801 - Aug-26-2019

Geez; if you're putting \n's in the string to handle nesting, just make a dummy file and run it.


RE: python command (2 and 3) ignores extra -c arguments - Skaperen - Aug-27-2019

what if i'm using -c because there is no writable file system available? can python(3) read a script from a pipe?