4 ms·
Yeah, perl borrows backticks from bash[3], so it's giving you syntax to do it directly, and it's long had strong support for opening a process using a very intu
by ben509 7y ago
Yeah, perl borrows backticks from bash[3], so it's giving you syntax to do it directly, and it's long had strong support for opening a process using a very intuitive syntax.
Python's subprocess module works quite well, but gets extremely verbose[4] as you try to do anything more complex than "run a command and get the output" and has some nasty gotchas[2].
I forget the invoke syntax, but doit[1] is basically a make replacement so calling the shell is pretty easy:
def task_something():
return {'actions': ['ls foo/', 'rm -r foo']}
And you can use outputs from one task as inputs for another, it tracks what's been done, etc.
[1]: https://pydoit.org/ https://pydoit.org/
[2]: https://docs.python.org/3/library/subprocess.html#subprocess.Popen.stderr https://docs.python.org/3/library/subprocess.html#subprocess...
[3]: https://perldoc.perl.org/5.30.0/perlop.html#qx%2f_STRING_%2f https://perldoc.perl.org/5.30.0/perlop.html#qx%2f_STRING_%2f
[4]: https://docs.python.org/3/library/subprocess.html#popen-constructor https://docs.python.org/3/library/subprocess.html#popen-cons...
- gerikson 7y agoHow can one do something like fork/exec in python? That's what I was thinking of when you mentioned "forking off jobs". There are a number of different ways to launch an external process from Perl, I think this StackOverflow answer summarizes them quite well: https://stackoverflow.com/a/800105 https://stackoverflow.com/a/800105 I'm an experienced Perl user, but I'm not as familiar with Python. In addition, I'm not really using Perl for sysadmin stuff, so I tend to try to keep stuff "within" Perl. As an example, I'd rather use the File::Find module than use backticks to invoke `find`. This has really nothing to do with functionality - I'm almost always on Linux, and the syntaxes are similarly hairy - it's just that usually you get more powerful functionality using the Perl functionality. (edit rearranged paragraphs)