From 397187bedc2bded78307b45283da145ce9556be9 Mon Sep 17 00:00:00 2001 From: Woose Date: Sat, 25 Jan 2025 02:11:31 +0300 Subject: [PATCH] update --- module4.ipynb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/module4.ipynb b/module4.ipynb index f07f088..b6892ec 100644 --- a/module4.ipynb +++ b/module4.ipynb @@ -253,6 +253,51 @@ "result = subprocess.run([\"ls\", \"this_file_does_not_exist\"])\n", "print(result.returncode)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Obtaining the output of a system command" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "result = subprocess.run([\"host\", \"8.8.8.8\"], capture_output=True)\n", + "\n", + "result = subprocess.run([\"host\", \"8.8.8.8\"], capture_output=True)\n", + "print(result.returncode)\n", + "\n", + "result = subprocess.run([\"host\", \"8.8.8.8\"], capture_output=True)\n", + "print(result.stdout)\n", + "\n", + "result = subprocess.run([\"host\", \"8.8.8.8\"], capture_output=True)\n", + "print(result.stdout.decode().split())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import subprocess\n", + "result = subprocess.run([\"rm\", \"does_not_exist\"], capture_output=True)\n", + "\n", + "import subprocess\n", + "result = subprocess.run([\"rm\", \"does_not_exist\"], capture_output=True)\n", + "print(result.returncode)\n", + "\n", + "import subprocess\n", + "result = subprocess.run([\"rm\", \"does_not_exist\"], capture_output=True)\n", + "print(result.returncode)\n", + "print(result.stdout)\n", + "print(result.stderr)" + ] } ], "metadata": {