I have a Python method that first changes the working directory to a specific path and then needs to execute a command - below is an extract of same:
def start_testing_binary(self, command, path, binary, args, config):
os.chdir(path)
cmd = command.replace('"', '') + binary+ args.replace('"', '') + config.replace('"', '')
return cmd
When I invoke the method with a system path having spaces in between I get below error:
start_testing_binary("myexe", "C:\\Users\\Project Work\\bin", ".exe", "-c" , "myinfo.ini")
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:\\Users\\Project Work\\bin"'
But when I hardcode its value in below call as mentioned:
os.chdir("C:\\Users\\Project Work\\bin")
The code does not reports any error - how can I fix this issue of having path being passed as argument?