原文
auto screen = executeShell(cmdLine);
auto s;//這樣聲明?
//無法推導`"s"`的類型.
//從`getPath`的傳回類型來看,可能是`string[]`.
//應該這樣
string[] s;
...
{
s = screen.output.findSplit("REG_SZ");
}
//但不編譯.
string[] getPath(string cmdLine)
{
auto screen = executeShell(cmdLine);
if (screen.status != 0)
{
writeln(cmdLine, " failed");
}
else
{
writeln("screen.output = ", screen.output);
auto s = screen.output.findSplit("REG_SZ");
writeln("s[0] = ", s[0]);
writeln("s[1] = ", s[1]);
writeln("s[2] = ", s[2]);
}
return (s.split(';')); // 未定義s
}
string[] getPath(string cmdLine)
{
import std.exception : enforce;
auto screen = executeShell(cmdLine);
enforce(screen.status == 0, format!"%s failed:\n%s"(cmdLine, screen.output));
//確定
writeln("screen.output = ", screen.output);
//後面略....
}
string[] getPath(string cmdLine)
{
string[] result;
auto screen = executeShell(cmdLine);
if (screen.status != 0)
{
writeln(cmdLine, " failed");
return null; // 在此(`無效`轉數組)
}
else
{
// ...
// 現在傳回s定義的.
return (s.split(';'));
}
}