0
import time
start_time = time.time()
for i in range (0, 10000):
    print('openssl rsautl -encrypt -pubin -inkey public.pem -in message.txt -out message_enc.txt')
print("--- %s seconds ---" % (time.time() - start_time))

I want to pass the string within the print method to the Linux command line and run it to get the average encryption time of RSA. I can not seem to figure out how to do this though. I could only find out how to pass arguments from the command line into a Python script.

Dave
  • 89
  • 1
  • 1
  • 6
  • `import os; os.system('ls -lrt')` – nehem Sep 19 '17 at 04:08
  • @itsneo, please don't encourage that. `os.system()` is deprecated in favor of `subprocess`, and invoking a shell unnecessarily is bad practice (not only inefficient, but often leads to security bugs). – Charles Duffy Sep 19 '17 at 04:08
  • Thanks for linking similar posts. I had no idea to use those keywords. I never want to create duplicate posts. Sometimes I just do not know good keywords to search for. – Dave Sep 19 '17 at 04:16

1 Answers1

2

You can do this with the subprocess module, which is built-in to Python.

>>> subprocess.call(["ls", "-l"])
0
Jeremy McGibbon
  • 3,527
  • 14
  • 22
  • 1
    See "Answer Well-Asked Questions" in [How to Answer](https://stackoverflow.com/help/how-to-answer). Questions which "have already been asked and answered many times before" should be closed, not answered. – Charles Duffy Sep 19 '17 at 04:06