open winword.exe from python with the OS module

2

Good evening I would like to know how I can execute an MS-DOS command from python.

I need to open WINWORD.EXE and this is the code I use

import os
r = os.system("C:/Program Files (x86)/Microsoft Office/root/Office16/")
T = r + os.system("/WINWORD.EXE")

but it does not work

    
asked by Mystic_Force 18.08.2018 в 04:21
source

1 answer

3

You almost have it, it should be something like this:

import os
r = os.system("C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE")

Considerations:

  • According to the documentation os.system() : Execute the command (a string) in a subshell. , meaning that the command must be indicated with the complete path in the parameter (you were just passing the route)
  • Also note that we are using the "natural" bars of Windows \ , but in this case it is necessary to escape them by adding a double bar \ , but a very useful and compatible between systems is to build the complete media path os.path.join
answered by 18.08.2018 / 15:45
source