-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fixed sporadic errors while executing a shell command #14
Conversation
Added shell commands logging
@@ -58,8 +58,8 @@ actual fun System.execute(command: String, vararg args: String): ProcessResult = | |||
close(errorPipe[writeEnd]) | |||
|
|||
//execute command | |||
val newArgs = listOf(command) + args | |||
val result = execvp(command, newArgs.map { it.cstr.ptr }.toCValues()) | |||
val newArgs = listOf(command) + args + null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does adding a null parameter to the arg list eliminates the need of adding empty parameter? If so then lets remove this extra parameter from where it is used now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it does. My "brew info cocoapods" command didn't work without this null-termination (and surprisingly even with an empty parameter either). But with this - it works.
Going to remove all these empty params throughout the project and check if it works everywhere.
I see that even in an existing project code those empty params aren't in every execute() call. Which is even weirder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I looked through exec man page many times but my eye never catch that arg list have to be null terminated 🤦
Thanks for pointing this out!
@@ -83,6 +83,26 @@ actual fun System.execute(command: String, vararg args: String): ProcessResult = | |||
retCode.value | |||
} | |||
|
|||
if (verbose) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just for debugging purposes or there are other applications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging solely
Yes, everything works now without explicit empty parameters |
Sometimes (literally sometimes, I see no consistent pattern) when you're trying to execute some shell command using
System.execute()
, it returns with returnCode 65280, anderror == null
,output == null
. Meanwhile, anexecvp()
documentation says that the list of arguments must be null-terminated.Also, added shell commands logging