Bug 7283 – Add error info to failed shell call

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-12T16:40:00Z
Last change time
2013-09-17T14:37:17Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-01-12T16:40:32Z
std.process.shell implements the system call with errnoEnforce, returning no useful information on what went wrong. Here's what a typical call produces: import std.exception; import std.process; import std.string; void main() { string cmd = "dmd -c blasudfasudfa.d"; shell(cmd); } std.exception.ErrnoException@std\process.d(364): (No error) ---------------- D:\dev\code\d_code\test.d(8): D main ---------------- I hate that confusing "No error" as well. I suggest we reimplement shell() so it does the following: import std.exception; import std.process; import std.string; void main() { string cmd = "dmd -c blasudfasudfa.d"; string filename = "blabiudasf"; auto result = system(cmd ~ "> " ~ filename); enforce(result == 0, format(`system("%s") returned %s`, cmd, result)); } Result: [email protected](12): system("dmd -c blasudfasudfa.d") returned 1
Comment #1 by andrej.mitrovich — 2013-09-17T14:37:17Z
In 2.063.2 this is now: Error: cannot read file blasudfasudfa.d std.exception.ErrnoException@std\process.d(3169): (No error) I think that's good enough, the error is now displayed above. Although I'm not sure whether that's Phobos outputting this or my console. If someone still wants to improve this, reopen the issue.