shell

When parsing strings, code is adding string contents and last part of string?

When parsing strings, code is adding string contents and last part of string? Question: I’m making my own shell in Python and trying to make it as user-friendly and customizable as possible. I’m having an issue when parsing command line strngs though.. I have a list of args to be passed to the command. When …

Total answers: 2

How to run bash script with getopt included in python?

How to run bash script with getopt included in python? Question: I am running a script in the ubuntu terminal and it works fine. ./run_script2.sh -b ./exercises/13_caching.py I want to run the same script in python os or subprocess but I am getting an error : ./run_script2.sh: line 36: getopt: command not found On line …

Total answers: 1

Python script for 'ps aux' command

Python script for 'ps aux' command Question: I have tried to use subprocess.check_output() for getting the ps aux command using python but it looks like not working with the large grep string. Can anyone have any solution? subprocess.check_output(‘ps aux | grep "bin/scrapy" | grep "option1" | grep "option2" | grep "option3" | grep "option4" | …

Total answers: 2

Pylint `–good-names` syntax on Linux

Pylint `–good-names` syntax on Linux Question: I’ve been using PyLint in Windows with such configuration: pylint –good-names (‘i’,’el’,’of’,’df’,’pd’,’Entity’) –bad-names (‘foo’,’bar’,’kek’,’KEK’) module but on Ubuntu, I get an exception while trying to parse good-names arguments (‘i’,’el’, …): /bin/bash: -c: line 6: syntax error near unexpected token `(‘ What is the correct way to provide such uncommon …

Total answers: 1

subprocess.run only accepting first argument

subprocess.run only accepting first argument Question: Using Python 3.10.6 trying to pass an argument to a command line opened via subprocess.run, I’ve tried toggling shell=True/False, as well as passing the second argument with the input variable, no luck. here is the relevant code: cmds = ([‘cmd’,’echo hello’]) cmd_result = subprocess.run(cmds, shell=False, check=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, …

Total answers: 1

execute os command from python that asks for confirmation

execute os command from python that asks for confirmation Question: Using python import os and os.system("create-object "+ more-specifications), I created a few hundreds of objects, which I now need to delete. I can list the objects created, including their unique id. To delete just one of them, on the command line, I issue delete-object –id …

Total answers: 1

Use python to execute shell command and redirect the output to a variable

Use python to execute shell command and redirect the output to a variable Question: I am trying to do 2 things with Python- Execute a command at the terminal Save the output of the above command to a variable. This is my code till now – import subprocess ip_address = "http://ipwho.is/104.123.204.11" query_reply = subprocess.run(["curl" , …

Total answers: 2

Python Shell: writing one byte and reading decimal data from a serial port

Python Shell: writing one byte and reading decimal data from a serial port Question: Problem Description: I am trying to retrieve all data stored on a device using rs232. How?: For this specific device, I need to: Step 1: send one byte (0x80) – uInt8 (8-bit unsigned integer) through a serial port (COM5) and expect …

Total answers: 1

Applescript call python failed

Applescript call python failed Question: I have developed an AppleScript which needs to call a python file. i.e autorun.py the Autorun.py start with import msoffcrypto import pathlib import os …. Both the AppleScript and the python file run fine. I even tried to call autorun.py in the terminal and that also runs with no problem. …

Total answers: 1