Questions tagged [shlex]

Use this tag for questions about the python shlex module.

From python.docs:

The shlex class makes it easy to write lexical analyzers for simple syntaxes resembling that of the Unix shell. This will often be useful for writing minilanguages, (for example, in run control files for Python applications) or for parsing quoted strings.

94 questions
0
votes
1 answer

Formatting String for subprocess.run "No closing quotation"

I have this command to run: 'xcopy /e "%s" "%s"'%(executablesPath + "\\*", sourcePath+"\\Executables\\") which is formatted to: xcopy /e "I:\Storage$\tools\Executables\*" "C:\Win10x64-1903\Executables\" and ran…
Aurora
  • 3
  • 1
0
votes
1 answer

Python subprocess: return value incorrect

I am writing a Python module which uses subprocess, to both see if a process has ran and also to get its PID. So far I have done the part of running processes. The processes clearly run, but there is something wrong with this code so it throws my…
John Tate
  • 780
  • 3
  • 10
  • 23
0
votes
1 answer

shlex.split() returning whole command as a single string

shlex.split() is not giving the proper output on the input string. In python interpreter, storing the input value in a variable produces the expected output. But if i execute via a script, shlex.split() output is incorrect and input string did not…
sandeep nagendra
  • 422
  • 5
  • 15
0
votes
3 answers

How to add parenthesis around a substring in a string?

I need to add parenthesis around a substring (containing the OR boolean operator) within a string like this: message = "a and b amount OR c and d amount OR x and y amount" I need to arrive at this: message = "(a and b amount) OR (c and d amount)…
Code Monkey
  • 800
  • 1
  • 9
  • 27
0
votes
1 answer

python subprocess and shlex

I am trying to get the following python code to work, I am just not able to get the syntax to work. Can someone assist? import subprocess import shlex subprocess.call(shlex.split('top -d 5 -n 1 -b -o %CPU | head -n 12 > output.txt'))
Jay Webster
  • 179
  • 1
  • 3
  • 12
0
votes
1 answer

| Not Working In Subprocess.call

Whenever I use a command in a subprocess with "|" in it doesn't work it has an output of Command "|" is unknown, try "in link help". Or when I put this: #!/usr/bin/python from subprocess import call from shlex import split interface =…
Hayden Seward
  • 29
  • 1
  • 6
0
votes
1 answer

shlex.split - list index out of range

I am currently trying to open a file and using shlex.split to segment the lines. Here is an example of 2 lines from the text file. set group address "Untrust" "This is a test group" set group address "Untrust" "This is a test group" add…
0
votes
0 answers

Using .Popen() and .shlex() to load files to deluge-console

I am having trouble getting a script to load files via deluge-console using .Popen() and .shlex(). I am using xubuntu and byobu on gnome-terminal. def torrentLoad(url): #client_run = subprocess.Popen(['deluged']]) sourceList =…
0
votes
0 answers

How to know the parameter value in shlex.split

I have string variable as --test abc -a a -b b c, which is parameters for my linux script. I am using python subprocess to execute this. This string might be have special character like backtic or ', --test \"it's my test\" -a a -b b c in this case,…
Nilesh
  • 20,521
  • 16
  • 92
  • 148
0
votes
1 answer

Command inside Python when name of I/O files must change

Ok, I have found how to execute complex commands inside Python with this post how to run my own external command in python script import shlex import subprocess proc = subprocess.Popen(shlex.split('gr_cp -option=90 inputfilename…
David
  • 1,155
  • 1
  • 13
  • 35
0
votes
1 answer

Python: subprocess.Popen().communicate() prints output of an SSH command to stdout instead of returning the output

Here's a copy of my python terminal: >> import subprocess >> import shlex >> host = 'myhost' >> subprocess.Popen(shlex.split('ssh -o LogLevel=error -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o UserKnownHostsFile=/dev/null -o…
user2824889
  • 1,085
  • 5
  • 16
  • 28
0
votes
2 answers

swift2 equivalent of python's shlex.split to preserve the whitespace within quoted strings

I'm looking for an existing swift2 function to split string input on whitespace while at the same time preserving whitespace within quoted strings. I have read stack overflow question 25678373. My question does not appear to be a duplicate. I…
StandardEyre
  • 113
  • 1
  • 1
  • 7
0
votes
2 answers

Escaping quotes in bash command using subprocess call and shlex

I am executing bash command using python's subprocess.call(). I am taking user input as an argument to my command like below. my_command = 'command -option1 {0} -option2 {1}'.format(arg1, arg2) Here arg1 and arg2 are user inputs but the problem is…
0
votes
2 answers

Invoking perl script with variable input and file output as arguments from python

I have a perl script that can be executed from the console as follows: perl perlscript.pl -i input.txt -o output.txt --append I want to execute this script from my python code. I figured out that subprocess.Popen can be used to connect to perl and…
0
votes
1 answer

Python - Popen(shlex.split(command), shell=False) - not working with ffmpeg

I am using Popen(shlex.split(command) to run an ffmpeg command which saves out wav files from a quicktime mov file and also save an ffmpeg log file at the same time. if I use this: command = './ffmpeg/ffmpeg -i /Users/me/Documents/MOVS/source.mov…
speedyrazor
  • 3,127
  • 7
  • 33
  • 51