0

If I run the following code in CMD, I get the following output:. curl -d "text=Hello there" http://bark.phon.ioc.ee/punctuator

Hello, there.

How do I run the same code using Python and store the output, i.e. "Hello, There" in a string

I tried the following python code:

import os
a=os.system('curl -d "text=Hello There" http://bark.phon.ioc.ee/punctuator')
type(a)
print(a)

I want to store the output in a variable, however type(a) gives int class <int> as output. How do I put my output in the form of a string and store Hello, there in a variable?

  • 2
    Does this answer your question? [Running shell command and capturing the output](https://stackoverflow.com/questions/4760215/running-shell-command-and-capturing-the-output) – JosefZ Jun 29 '21 at 17:40

1 Answers1

-1

import os; os.system('cmd /k "date"')

  • 2
    Running with __deprecated__ `os.system` in background `C:\Windows\System32\cmd.exe` with option `/c` to run one more command process as specified in Python script with `cmd` and with the option `/k` to output with `date` the current local date and then keep both `cmd.exe` instances running until the user exits the second command process is definitely not what the questioner asked for. – Mofi Jun 30 '21 at 06:05