regading detection of stdin
Hugo Florentino
hugo at acdam.cu
Thu Dec 5 16:06:52 PST 2013
Hi,
I was trying to do something like this (using dmd.2.064.2 both from
Windows and Linux), but if nothing is passed from stdin and no parameter
is provided, the application freezes:
import std.stdio, std.file: readText;
int main(string[] args) {
string s;
switch (args.length) {
case 1:
if ((s = stdin.readln()) is null)
writeln("No argument passed as parameter or from stdin.");
else
writeln("Argument passed from stdin succesfully stored in
variable s.");
scope (failure) {
writeln("Error reading from stdin.");
return -1;
}
break;
case 2:
s = readText(args[1]);
scope (failure) {
writeln("Error reading from file passed as parameter.");
return -2;
}
writeln("Argument passed as parameter succesfully stored in
variable s.");
break;
default:
writeln("Incorrect number of parameters. Maximum is one.");
return -3;
}
return 0;
}
Where is the problem?
Regards, Hugo
More information about the Digitalmars-d-learn
mailing list