| 2871 | |
| 2872 | #[allow(clippy::too_many_lines)] |
| 2873 | fn execute_shell_command( |
| 2874 | shell: &str, |
| 2875 | command: &str, |
| 2876 | timeout: Option<u64>, |
| 2877 | run_in_background: Option<bool>, |
| 2878 | ) -> std::io::Result<runtime::BashCommandOutput> { |
| 2879 | if run_in_background.unwrap_or(false) { |
| 2880 | let child = std::process::Command::new(shell) |
| 2881 | .arg("-NoProfile") |
| 2882 | .arg("-NonInteractive") |
| 2883 | .arg("-Command") |
| 2884 | .arg(command) |
| 2885 | .stdin(std::process::Stdio::null()) |
| 2886 | .stdout(std::process::Stdio::null()) |
| 2887 | .stderr(std::process::Stdio::null()) |
| 2888 | .spawn()?; |
| 2889 | return Ok(runtime::BashCommandOutput { |
| 2890 | stdout: String::new(), |
| 2891 | stderr: String::new(), |
| 2892 | raw_output_path: None, |
| 2893 | interrupted: false, |
| 2894 | is_image: None, |
| 2895 | background_task_id: Some(child.id().to_string()), |
| 2896 | backgrounded_by_user: Some(true), |
| 2897 | assistant_auto_backgrounded: Some(false), |
| 2898 | dangerously_disable_sandbox: None, |
| 2899 | return_code_interpretation: None, |
| 2900 | no_output_expected: Some(true), |
| 2901 | structured_content: None, |
| 2902 | persisted_output_path: None, |
| 2903 | persisted_output_size: None, |
| 2904 | sandbox_status: None, |
| 2905 | }); |
| 2906 | } |
| 2907 | |
| 2908 | let mut process = std::process::Command::new(shell); |
| 2909 | process |
| 2910 | .arg("-NoProfile") |
| 2911 | .arg("-NonInteractive") |
| 2912 | .arg("-Command") |
| 2913 | .arg(command); |
| 2914 | process |
| 2915 | .stdout(std::process::Stdio::piped()) |
| 2916 | .stderr(std::process::Stdio::piped()); |
| 2917 | |
| 2918 | if let Some(timeout_ms) = timeout { |
| 2919 | let mut child = process.spawn()?; |
| 2920 | let started = Instant::now(); |
| 2921 | loop { |
| 2922 | if let Some(status) = child.try_wait()? { |
| 2923 | let output = child.wait_with_output()?; |
| 2924 | return Ok(runtime::BashCommandOutput { |
| 2925 | stdout: String::from_utf8_lossy(&output.stdout).into_owned(), |
| 2926 | stderr: String::from_utf8_lossy(&output.stderr).into_owned(), |
| 2927 | raw_output_path: None, |
| 2928 | interrupted: false, |
| 2929 | is_image: None, |
| 2930 | background_task_id: None, |