-
-
Notifications
You must be signed in to change notification settings - Fork 466
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
Getting one garbage character from container.exec() #736
Comments
jamesmurdza
changed the title
Getting one garbage character
Getting one garbage character in stdout
Jun 10, 2023
jamesmurdza
changed the title
Getting one garbage character in stdout
Getting one garbage character from container.exec()
Jun 10, 2023
const readStream = (stream: stream.Duplex) => {
let output: string = "";
return new Promise<string>((resolve, reject) => {
stream.on("data", (chunk: string) => {
output += chunk;
});
stream.on("end", () => {
// handle garbage
resolve(output.trim().split("\n").map(processString).join("\n"));
});
});
function processString(str: string): string {
const out = Buffer.from(str, "binary");
if (out.readUInt8(0) === 1) {
return out.toString("utf8", 8);
} else {
return out.toString("utf8", 0);
}
}
}; May be this function can help you. |
Interesting, I will try this. Any explanation why this would work? |
@Fhwang0926 Were you able to figure out any solution? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've written two helper functions using Dockerode. The idea is to run a command synchronously and then return the results as a string.
It works well, except each chunk that is returned by stream.on('data') starts with a garbage character, like "X", "*", "!", etc. I can't figure out why.
This happens for multiple commands, such as "bash" and "cat".
Help is much appreciated!
My code below:
The text was updated successfully, but these errors were encountered: