Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1584

Python • Re: Rapberry syntax error

$
0
0
AwkOut=subprocess.run("""["grep", "-ni", "'^\([^;]*;\)\{""" + str(indexcolonne) + """\}""" + Cols[1] + """'", """ + BasedeDonnees + """]""", capture_output=True, text=True, shell=True)

I never found the syntax for it.
I would recommend passing a constructed string to 'subprocess.run', then you can print what that string contains -

Code:

s = """["grep", "-ni", "'^\([^;]*;\)\{""" + str(indexcolonne) + """\}""" + Cols[1] + """'", """ + BasedeDonnees + """]"""print("s =", s)AwkOut=subprocess.run(s, capture_output=True, text=True, shell=True)
When I run that with 'indexcolonne=0', 'Cols=["a","b"]' and 'indexcolonne="c"', I get a single literal string as I would have anticpated from how it is coded (assuming Python) ...

Code:

s = ["grep", "-ni", "'^\([^;]*;\)\{0\}b'", c]
I am guessing that should not have been a single literal string, but a list of strings, command name and arguments.

Maybe explain what you want the command to be, provide examples.

Statistics: Posted by hippy — Sun Jul 20, 2025 5:58 pm



Viewing all articles
Browse latest Browse all 1584

Trending Articles