indeed. There are better options than the one I attempted. Thanks for the advice
Am Mi., 28. Juli 2021 um 18:19 Uhr schrieb Chris Angelico <ros...@gmail.com >: > On Thu, Jul 29, 2021 at 2:10 AM joseph pareti <joeparet...@gmail.com> > wrote: > > > > The following code fails as shown in the title: > > > > > > > > > > > > > > *import subprocesscmd = 'ls -l > > > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 > > | awk "{print $9 }"'process = subprocess.Popen([cmd], > > stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr = > > process.communicate()print('stdout ',stdout)print('stderr ',stderr)* > > > > ---- > > > > Traceback (most recent call last): > > File "PreProcess_1a.py", line 3, in <module> > > process = subprocess.Popen([cmd], stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line > 854, > > in __init__ > > self._execute_child(args, executable, preexec_fn, close_fds, > > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line > > 1702, in _execute_child > > raise child_exception_type(errno_num, err_msg, err_filename) > > FileNotFoundError: [Errno 2] No such file or directory: 'ls -l > > > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 > > | awk "{print $9 > > > > First off, you'll want to post code in a way that keeps the > formatting, otherwise it becomes very hard to read. > > But the immediate problem here is that Popen takes an array of command > arguments, NOT a shell command line. You cannot invoke ls and pipe it > into awk this way. > > Don't think like a shell script. Python has very good > directory-listing functionality, and you will very very seldom need to > shell out to pipelines. Figure out what you actually need to learn > from the directory listing and get that information directly, rather > than trying to use two external commands and text parsing. It's far > FAR easier, cleaner, and safer that way. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 -- https://mail.python.org/mailman/listinfo/python-list