0

I wrote a Python code with the os module:

import os
os.system("python")

When I run this code in PowerShell/command prompt, it will open the python interpreter in PowerShell/command prompt.

Now I want to extend the code which will automatically write the next lines of code in that python interpreter itself (which is opened in the PowerShell already).

For example:-

enter image description here

The above code opened this in the PowerShell.

Now I want to exit the Python interpreter (This is for example) in this PowerShell window with python's inbuilt function exit().

Thanks!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Robin Kadian
  • 33
  • 1
  • 10
  • 3
    Using [System.Windows.Forms.SendKeys](https://stackoverflow.com/a/54999779/503046) might work. Anyway, the problem seems a bit strange. What are you [trying to achieve](https://xyproblem.info/)? – vonPryz Jun 03 '21 at 20:07
  • 2
    A [XY problem?](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – JosefZ Jun 03 '21 at 20:12
  • PowerShell does not run Python code or vice versa. You can call powershell.exe from python and have PowerShell.exe run the PowerShell code and vice versa. Python has no idea what PowerShell commands are and vice versa. To pass (AutoIT, SendKeys, Selenium, etc...) stuff between the environment, you need to know which machine is useable. You are aksing for GUI automation. – postanote Jun 03 '21 at 22:33
  • @vonPryz I achieved the python interpreter in PowerShell via python code. Now I want to extend the code which can send commands to the python interpreter (In the picture) – Robin Kadian Jun 05 '21 at 06:54

0 Answers0