Unable to execute date command in subprocess.call

Asked 2 years ago, Updated 2 years ago, 95 views

I'd like to execute the following command, but I don't know the correct format.How should I fix it?

subprocess.call("date-set="January 1, 2017 01:02:03")

Note:
If you try to do it, you'll see the following for this line:
SyntaxError: invalid syntax
We have determined that it is a formatting error because we cannot execute it with the error

python python3 linux

2022-09-30 21:48

1 Answers

To include " in the string, write \" or enclose it with '.

subprocess.call("date-set=\"January 1, 2017 01:02:03\"")
subprocess.call('date-set="January 1, 2017 01:02:03")

Also, if you specify it in list format, you should not need quotation marks to enclose the date.

subprocess.call(["date", "-set=2017/01/01/02/03")


2022-09-30 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.