0

Any way to make python os.system module code universally work ?

For example:

Below is easy but it is not universal means works if you run in linux dosent work if you run in windows. tell me if you know to make below universal i.e across all O.S platforms.

import os

os.system("sshpass -p 'your password' scp /opt/pysftp_server.txt root@172.19.113.87:/home")
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
sudhir tataraju
  • 1,159
  • 1
  • 14
  • 30
  • 2
    You mean like checking the platform the program's running on and then work out which programs are available/can be used to do the same thing and executing the command appropriate for the host? – Jon Clements Sep 15 '18 at 18:24
  • 1
    use modules that work on win and linux and do the same without using the systems programs ... f.e. [using `paramiko`](https://stackoverflow.com/a/69596/7505395) - see [how-to-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh](https://stackoverflow.com/questions/68335/how-to-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh) for copying fiiles via ssh – Patrick Artner Sep 15 '18 at 18:26
  • @JonClements Is that a viable strategy? For windows there might be none installed - or multiples (SSH over win 10 powershell, putty, ...) some different ways to ssh into some other uri. – Patrick Artner Sep 15 '18 at 18:30
  • @PatrickArtner it's effectively what some modules do as per your suggestion (or they just wrap system APIs to a common interface and delegate calls appropriately). It's not particularly viable/pleasant to do if you can't find one of 'em though. – Jon Clements Sep 15 '18 at 18:32
  • @JonClements : Yes I mean like checking the platform the program's running on and then work out which programs are available/can be used to do the same thing and executing the command appropriate for the host ! – sudhir tataraju Sep 16 '18 at 08:15
  • 1
    @sudhir okay... so you can check the platform in the `sys` module and then you'll need to research all (or at least the common (if any)) ways you can do that on the platform and then code up the appropriate calls. – Jon Clements Sep 16 '18 at 08:16

0 Answers0