Piping from terminal into D program

eXodiquas exodiquas at gmail.com
Sat Sep 4 15:41:51 UTC 2021


Hello everyone,

I created a small little D program that reads in a string from 
the command line and shuffles the letters of the nouns a bit 
around. This is pretty straight forward, but what I see now 
happening is a bit strange, at least for me.

I am reading the args out of the main function arguments.

```d
void main(string[] args) {
   args.writeln();
}
```

this works fine whenever I call the program like `./nounscramble 
"Hello, my name is Earl!"` the string shows up in `args[1]`. But 
when I call `echo "Hello, my name is Earl!" | ./nounscramble` it 
does not show up in the args array, the only thing showing up is 
the name of the executable (which is expected).

My question is now, can someone explain what I am doing wrong? 
Maybe I misunderstood the pipe in Linux systems and it is obvious 
for someone who knows how this works exactly, or maybe D works 
differently with pipes and I havn't found the correct 
documentation.

Thanks in advance. :)

eXodiquas


More information about the Digitalmars-d-learn mailing list