Feature request: Command queue via file
galiagante opened this issue · 4 comments
Sample use case:
A file containing nuanced/complex commands (e.g.):
cat commands.list
echo "one" && du -hcs ./one
echo "two" && du -hcs ./two
echo "three" && du -hcs ./three
To be executed in parallel like so:
parallel < commands.list
This would reproduce a useful command-line behavior similar to what's found in recent version of GNU Parallel.
As a work-around, perhaps there's a way to do this in the current version using an alternate syntax?
It works if you enter target/debug/parallel :::: inputs
or target/debug/parallel ::: < inputs
but I can look into it.
This is a mental note on the topic:
I think only a limited number of operating systems could use this feature (Linux + BSD). I see that it is possible to determine the owner of stdin on *nix systems that feature a proc
filesystem by using the readlink
function on /proc/self/fd/0
. If the link points to /dev/pts
then there probably isn't any redirection, but if it points to something else then there is input redirection. IE:
$ readlink /proc/self/fd/0
/dev/pts/4
$ readlink /proc/self/fd/0 < inputs
/home/mmstick/Sources/parallel/inputs
This feature has now been implemented. There's three ways to do this now:
parallel :::: inputs.list
parallel < inputs.list
parallel ::: < inputs.list
Also discovered a bug where inputs as commands wasn't working as intended, which is now fixed.
Relevant source code for detecting input redirection in Rust:
pub fn input_was_redirected() -> Option<PathBuf> {
if let Ok(link) = fs::read_link("/proc/self/fd/0") {
if !link.to_string_lossy().starts_with("/dev/pts") {
return Some(link)
}
}
None
}