I have a python
script that prints to the stdout a list of files, for example:
$ ./myscript.py
"file a.txt" "file b.txt" "file c.txt"
I want to open these files in LESS
$ less <(./myscript.py)
But I get the following error:
-bash: /dev/fd/63: Permission denied
$ Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe
I think it may be the same problem as @Jon-Clements refers to in grep: broken pipe error python 2.2, i.e. the pipe is finished; but I'm not sure. I also tried (maybe incorrectly) the solution by @chepner store return value of a Python script in a bash script but it gives the same error.
How can I fix this? I know that mixing BASH and Python is bad practice.
BTW, the python script is using a loop around the following statement to produce the list of filenames:
print('"'+filename+'"',sep=" ",end=' ',)
Also, when I copy and paste the output manually to less
, it works fine.