0

I am encountering an unusual issue on a Windows 7 machine where my Python script works perfectly when run in PowerShell with a blue background (which I assume to be Windows PowerShell), but fails when run in PowerShell with a black background (which appears to be PowerShell Core, although it's invoked via powershell.exe).

In summary:

1. PowerShell with a blue background, launched from the Start menu, works flawlessly.

2. PowerShell with a black background, launched from "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe", does not work with my script.

Here is the relevant part of my Python code:

import subprocess

rexdeskconvert_command = 'ReXdeskConvert.exe convert-folder -F mf4 -i "{}" -o "{}" -s can0 "{}"'.format(input_folder, output_folder, dbc_file_path)

subprocess.run(['powershell.exe', '-Command', rexdeskconvert_command])

This subprocess.run command works without issue in the blue background PowerShell, but fails in the black background PowerShell.

Questions:

  1. How can I modify my Python code to consistently work with the blue background PowerShell (Windows PowerShell), which is the environment in which my script runs correctly?
  2. Is there a way to set the blue background PowerShell (Windows PowerShell) as the default on my Windows 7 machine, so that scripts and commands always run in that environment?

Additional context: The script is intended to run a specific executable (ReXdeskConvert.exe) with arguments, and the necessary software is installed in the specified directories.

I'm at a loss as to why the background colour seems correlated with the script’s success, and I'd really appreciate any guidance or insight into this issue.

Suprava
  • 69
  • 6
  • Check environment variables set on machine accordingly use relative or absolute path inside code to execute/access .exe process or file.You can also write .bat file to execute command on windows OS. – devesh Aug 18 '23 at 07:34
  • You can download and use git bash terminal instead. Windows black background terminal is cmd.exe not bash – PatioFurnitureIsCool Aug 18 '23 at 07:37
  • The path `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe` opens Windows Powershell (Black background) which doesn't work. Is there something specific I should look for in the environment variables that might be causing this discrepancy between the blue and black background PowerShells? – Suprava Aug 18 '23 at 07:38
  • @PatioFurnitureIsCool is there a way to stick to PowerShell? I mean, why do we have the colour discrepancy even though both files (PowerShell on the start menu & powershell.exe in C drive) are directed to the same directory? `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe` – Suprava Aug 18 '23 at 07:45
  • “fails in the black background PowerShell.” - fails how? Is there an error message? Your “black background” Powershell is still Windows PowerShell by the sounds of things if it’s launched via Powershell.exe. The executable for PowerShell Corr is pwsh.exe. You can echo out the ```$PSVersionTable``` variable to prove this either way… – mclayton Aug 19 '23 at 08:22
  • @mclayton the `rexdeskconvert_command` command works on the blue background Powershell and not black. I cannot fix that as of now. My question is why does the start menu open the Powershell (blue background) and where is the .exe file of it? My problem will be solved if i get the Blue background Powershell exe path. – Suprava Aug 19 '23 at 08:39
  • @Suprava - see https://stackoverflow.com/questions/65862733/differences-between-blue-background-and-black-background-powershell for details about the background color.r If you post the error message / failure symptoms we can maybe help work out what's going on, but without that there's nothing more I can really add myself... – mclayton Aug 19 '23 at 11:55

0 Answers0