0

I have a python 3.x script that requires accurate time. I use the following, within OSX 10.13.6

sudo ntpdate -vu time.apple.com

How can I execute this within python? Or is there a python native way to make sure my machine is properly synched with a time server?

Unknown Coder
  • 6,201
  • 19
  • 73
  • 120
  • 3
    can you not just call the command using subprocess? https://docs.python.org/library/subprocess.html `subprocess.run(["sudo", "ntpdate", "-vu", "time.apple.com"], capture_output=True, text=True).stdout` – Boris Sep 09 '19 at 03:17
  • 1
    you can also try `os.system("sudo ntpdate -vu time.apple.com")` if you don't need result in variable. – furas Sep 09 '19 at 03:44
  • @furas or with subprocess `subprocess.run("sudo ntpdate -vu time.apple.com", shell=True)` – Boris Sep 09 '19 at 03:56
  • @Boris subprocess has many functions to do the same :) – furas Sep 09 '19 at 04:00
  • Possible duplicate of [Calling an external command in Python](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – Boris Sep 09 '19 at 04:13

0 Answers0