On occasion process substitution will not work as expected. Here is an example:
Input:
gcc <(echo 'int main(){return 0;}')
Output:
/dev/fd/63: file not recognized: Illegal seek
collect2: error: ld returned 1 exit status
Input:
But it works as expected when used with a different command:
grep main <(echo 'int main(){return 0;}')
Output:
int main(){return 0;}
I have noticed similar failures with other commands (i.e. the command expecting the file from the process substitution can't use /dev/fd/63
or similar). This failure with gcc
is just the most recent. Is there some general rule that I should be aware of to determine when process substitution will fail in this way and should not be used?
I am using this BASH version on Ubuntu 12.04 (I've also seen this in arch and debian):
GNU bash, version 4.3.11(1)-release (i686-pc-linux-gnu)
illegal seek
looks like the answer - the|pipe
thatbash
points the executed program to is not a seekable file. probably if you cannot successfullyecho data | command /dev/fd/0
at a program then you'll have similar luck w/<(cmd)
. It doesn't provide an on-disk file - it just substitutes an argument that points to a pipe file descriptor.gcc -xc <(echo 'int main(){return 0;}')
(which sets the language toC
explicitly).psub
command, and dogcc (echo 'int main(){return 0;}' | psub -s .c)