Home > Software design >  Run arbitrary Python after 'py' command
Run arbitrary Python after 'py' command

Time:11-15

Suppose I have the following Fowershell function:

  function test {
        py
        print('hello world')
    }

when run, it opens Python in Powershell, but it doesn't execute the code following the 'py' command. how can I make it do that WITHOUT creating a file?

Edit: after quitting python, it outputs Unable to initialize device PRN. I think it's executing print() after py closes

CodePudding user response:

You can use Python's -c command line flag:

python -c "print('hello world');print('Second line')"                                                                                                                             
>> hello world
>> Second line
  • Related