Skip to content
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

Merged
merged 2 commits into from
Feb 21, 2022

Conversation

amatsegor
Copy link
Contributor

@amatsegor amatsegor commented Feb 20, 2022

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, and error == null, output == null. Meanwhile, an execvp() documentation says that the list of arguments must be null-terminated.

Also, 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
Copy link
Contributor

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.

Copy link
Contributor Author

@amatsegor amatsegor Feb 21, 2022

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.

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging solely

@amatsegor
Copy link
Contributor Author

amatsegor commented Feb 21, 2022

Yes, everything works now without explicit empty parameters

@vkormushkin vkormushkin merged commit b213576 into Kotlin:master Feb 21, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants