0

Preface: I am a beginner to Python

Problem statement: I am writing a script wherein I will be launching an application (Gotit.exe) sitting at particular path lets say D:\Some Folder\SomeMore Folder\AgainFolder\myPythonFolder\Gotit.exe. I have kept the python-script also in myPythonFolder.

I am accessing the folder path via os.path.dirname(os.path.realpath(__file__)) and selecting particular application by appending it with \Gotit.exe but when passing the same appended string stored in a variable i.e. GotitexePath to os.system(GotitexePath) its throwing error as,

'D:\Some ' is not recognized as an internal or external command, operable program or batch file.**

Kindly help me out to solve the said issue

I am using python 3.8.2 on Win10 Machine

khelwood
  • 55,782
  • 14
  • 81
  • 108
delve123
  • 47
  • 5
  • 2
    Please update your question with your code. See [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Lucan Jun 08 '20 at 08:38
  • 1
    you have no slash issue, you have a blank issue, try double quotes around it – Turo Jun 08 '20 at 08:38
  • correct @Turo, I have tried below solution and it seems its not working for me, can you please point if I am doing something wrong – delve123 Jun 09 '20 at 17:57

2 Answers2

1

The error is pointing to Some Folder name. Since there is a space in path you provide, the system doesn't know whether it is a part of folder name or it is a next argument to the command.

You need to escape the blank space. There are multiple ways to to it. For example wrap the path with double quotes:

"D:\Some Folder\SomeMore Folder\AgainFolder\myPythonFolder\Gotit.exe"

For more ways see this post

YTerle
  • 2,606
  • 6
  • 24
  • 40
  • Thanks for replying.Since the path is in variable not sure how to double-quote it, could you please suggest a workaround for the same ? – delve123 Jun 09 '20 at 17:38
  • I have tried solution given in [link](https://stackoverflow.com/questions/20056548/printing-double-quotes-around-a-variable) , still same error – delve123 Jun 09 '20 at 17:54
0
os.system("\"%s\"" % GotitexePath)

A the previous replies say, you need to add additional quotation marks around the path for the windows command line.

zariiii9003
  • 356
  • 1
  • 7