1

i have issue which drives me crazy. i have a command to be executed which success in CMD and fails in windows power shell. i am trying to execute this command from python, but it seems that python executing it using powershell. is it possible to force it to use cmd?! also i need to read the output of the command.

command is :

sfdx force:org:list

Python code :

import subprocess
climain = "sfdx force:org:list"
query = subprocess.check_output(climain, shell=True)
return json.loads(query)

so i need to force python to use cmd instead of powershell and return the output.

UDPATE 1 :

i have tried this .. to force working with cmd

>>> import subprocess
>>> proc = subprocess.Popen('cmd.exe', stdin = subprocess.PIPE, stdout = subprocess.PIPE)
>>> stdout, stderr = proc.communicate('IPCONFIG')
>>> stdout

but its not printing the output of IPCONFIG command.. it just gives this.

Microsoft Windows [Version 10.0.17763.195] (c) 2018 Microsoft Corporation. All rights reserved. (venv) C:\Users\webapp\Desktop\ed1\ed1>More?
  • May help smhw https://stackoverflow.com/a/5486820/10473393 – Alexander Santos Oct 01 '21 at 15:54
  • That doesn't sound right. There's literally nothing that any executable needs to do to communicate with another process using pipes. *cmd.exe* is no exception. You may have to redirect `stderr` as well. – IInspectable Oct 02 '21 at 11:27

0 Answers0