0

Im using raspberry pi and i want to control another windows machine by sending command using winexe. i can use the command directly from the terminal. However if i use python to send the command, the command seems invalid.

i can run this command at the terminal with no problem

 winexe -U pc1%ppc1 //ipaddress 'netsh interface show interface'

i know its not practical to use os.system but the syntax works fine for me if use it with python

 os.system('winexe -U pc1%ppc1 //ipaddress "netsh interface show interface"')

when i want to quote another syntax. with the terminal i run it and it works perfectly fine

 winexe -U pc1%ppc1 //ipaddress 'netsh interface set interface "Local Area Connection admin=disable'

How can i use python to run the syntax for above line? i have already tried with

 os.system('winexe -U pc1%ppc1 //ipaddress "netsh interface set interface "Local Area Connection" admin=disable"')

but the code cant run its just loading forever. its like i quote it wrongly. anyway to fix this?

1 Answers1

0

You have not said exactly what error it gives you, however

i think the problem could be that you try to use 3 nested quotes

'  " " " " '

but you should use a third type of quote (`) to make it works

'  "  ` ` " ' 

so

os.system('winexe -U pc1%ppc1 //ipaddress "netsh interface set interface `Local Area Connection` admin=disable"')
Mirko Conti
  • 470
  • 2
  • 16
  • using above code, it detect my code start from winexe and finish until set interface. it totally ignore Local Area Connection syntax – user2906282 Sep 22 '16 at 09:09
  • have you try this? os.system(\`winexe -U pc1%ppc1 //ipaddress 'netsh interface set interface "Local Area Connection" admin=disable'\`). Maybe the netsh command does not handle the ` quote. – Mirko Conti Sep 22 '16 at 14:12
  • still not working. it just prompt me to use correct syntax with winexe – user2906282 Sep 22 '16 at 15:57
  • as a last idea I would try to use the subprocess module ( https://docs.python.org/2/library/subprocess.html) to send pars separately. – Mirko Conti Sep 22 '16 at 16:14
  • actually i have already tried subprocess but with subprocess, it says login invalid – user2906282 Sep 23 '16 at 02:53