-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: os/exec: add String() to *exec.Cmd #21707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's pretty easy to do this yourself if you're in charge of constructing the command line. |
Yeah, same thought as @robpike, and in deed you have better control yourself, and can log.Error("exec", "args", cmd.Args) |
In general, we can write any program without String(). |
Seconded, fmt.Stringer is a better choice.
…On Thu, 31 Aug 2017, 15:56 hirochachacha ***@***.***> wrote:
In general, we can write any program without String().
We can always write own string representation easily. String() is not an
intrinsic method.
But it doesn't mean String() is useless, programmers are sometimes lazy.
I feel that *exec.Cmd is a good candidate for fmt.Stringer because the
string representation can express differences between each instances
effectively.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#21707 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAcAyzTAXcwaFyys8polROZ0AiK4kmUks5sdksKgaJpZM4PIMoL>
.
|
I disagree. A Cmd is a lot more (a LOT!) than a set of arguments, and implementing Stringer for that type would, by this approach printing only the args, suppress the rest. |
Should Sting() keep all information? I thought that is more like GoString()'s job. I can see text/template/parse/node.go. Those AST have own String() method. Similarly, I think cmd+args express exec.Command enough. |
(Maybe "text/template/parse" is not a good example. I cannot imagine good examples. Sorry.) |
Rob's comment #21707 (comment) seems like the most important argument against - why should an exec.Cmd stringify as the command being run? Why not the result? Why not some other detail of the struct? You could argue that it should have a ShellCommand() string method or something like that, to get just a printable command, but even that is very difficult and not clearly a good idea, since exec.Cmd doesn't use the shell to execute the command. (Well, except on Windows.) Declining proposal. |
I see. Thank you for your opinions. |
I propose adding String() to *exec.Cmd. For example,
will print
or
This is useful when we want to improve error messages.
The text was updated successfully, but these errors were encountered: