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

Stream doesn't close after exec log #374

Closed
yooouuri opened this issue Feb 18, 2024 · 0 comments
Closed

Stream doesn't close after exec log #374

yooouuri opened this issue Feb 18, 2024 · 0 comments

Comments

@yooouuri
Copy link

yooouuri commented Feb 18, 2024

First, thanks for this crate. I have the following code:

#[tauri::command]
async fn create_exec_listener(container_name: String, command: String, app_handle: AppHandle) {
    // let handle = app_handle.clone();
    let docker = Docker::connect_with_socket("/Users/youri/.colima/docker.sock", 120, API_DEFAULT_VERSION).unwrap();

    let exec = docker
        .create_exec(
            container_name.as_str(),
            CreateExecOptions {
                attach_stdout: Some(true),
                attach_stderr: Some(true),
                attach_stdin: Some(true),
                tty: Some(true),
                cmd: Some(vec!["sh"]),
                ..Default::default()
            },
        )
        .await
        .unwrap()
        .id;

    if let StartExecResults::Attached {
        mut output,
        mut input,
    } = docker.start_exec(&exec, None).await.unwrap()
    {
        input.write(command.as_bytes()).await.ok();

        while let Some(Ok(output)) = output.next().await {
            println!("{}", output);
        }

        println!("done");
    }
}

How can I break out of the while loop? I need to send the user an event when the command is done.

@yooouuri yooouuri changed the title stream doesn't close after exec log Stream doesn't close after exec log Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant