-2

I have a program called MicroSIP. When I double click it, it opens and register to a remote server according to a .ini file. everything is fine so far. I have a python script in which I want to close the process of MicroSIP.exe and running it again. I'm able to do so, but for some reason, when it opens again, it's like it doesn't use the .ini file like it does when double-clicked.

Does anyone know why does it happen?

This is my code for closing the process and running it again:

os.system("TASKKILL /F /IM MicroSIP.exe")
os.system('"C:\Users\Tamir\Downloads\MicroSIP-Lite-3.10.5\MicroSIP.exe"')
sipsorcery
  • 30,273
  • 24
  • 104
  • 155
tamird14
  • 481
  • 1
  • 6
  • 19

2 Answers2

4

It is actually the working directory issue. In your Python script make sure that you the directory containing the exe is made the home directory and then the exe is executed.

Vikas Ojha
  • 6,742
  • 6
  • 22
  • 35
  • 2
    can you explain more what do you mean? I don't understand – tamird14 Sep 17 '15 at 12:48
  • 2
    MicroSIP apparently looks for its INI file in the working directory. That means your python process needs to cd to that directory before calling os.system to exec microsip. Use os.chdir() for this. – jarmod Sep 17 '15 at 13:01
2

You can check your script working directory this way:

import os
print os.getcwd()

For sure it is working in a different directory than your .exe application

A very simple workaround would involve using absolute paths:

os.system("TASKKILL /F /IM MicroSIP.exe")
os.chdir('"C:\\Users\\Tamir\\Downloads\\MicroSIP-Lite-3.10.5\\"')    
os.system('"C:\\Users\\Tamir\\Downloads\\MicroSIP-Lite-3.10.5\\MicroSIP.exe"')

To understand more and better I suggest you to read this question

Pitto
  • 8,229
  • 3
  • 42
  • 51