Skip to content

Commit

Permalink
fix more crashes on windows by taking ownership of stdin/stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Kobusch committed Oct 4, 2023
1 parent 0392a34 commit 2253c14
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plotly_kaleido/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::num::ParseIntError;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -137,7 +138,7 @@ impl Kaleido {
let p = p.to_str().unwrap();
let p = String::from(p);

let process = Command::new(p.as_str())
let mut process = Command::new(p.as_str())
.current_dir(self.cmd_path.parent().unwrap())
.args([
"plotly",
Expand All @@ -156,14 +157,14 @@ impl Kaleido {

{
let plot_data = PlotData::new(plotly_data, format, width, height, scale).to_json();
let mut process_stdin = process.stdin.unwrap();
let mut process_stdin = process.stdin.take().unwrap();
process_stdin
.write_all(plot_data.as_bytes())
.expect("couldn't write to Kaleido stdin");
process_stdin.flush()?;
}

let output_lines = BufReader::new(process.stdout.unwrap()).lines();
let output_lines = BufReader::new(process.stdout.take().unwrap()).lines();
for line in output_lines.flatten() {
let res = KaleidoResult::from(line.as_str());
if let Some(image_data) = res.result {
Expand Down

0 comments on commit 2253c14

Please sign in to comment.