1+ use std:: env;
12use std:: io:: Write ;
23use std:: path:: PathBuf ;
34use std:: process:: { Child , Stdio } ;
@@ -13,12 +14,14 @@ use crate::event::Event;
1314pub fn send_events ( command : & str , events : & [ Event ] ) {
1415 match serde_json:: to_string_pretty ( & events) {
1516 Ok ( events_json) => {
16- if let Some ( tempfile_path) = write_events_file ( events_json. clone ( ) ) {
17- if let Some ( ref mut child_process) = spawn_process ( command, tempfile_path) {
18- if let Some ( ref mut p_stdin) = child_process. stdin . as_mut ( ) {
19- if let Err ( error) = writeln ! ( p_stdin, "{}" , events_json) {
20- debug ! ( "Could not write events to executable stdin: {:?}" , error) ;
21- }
17+ let tempfile_path = match env:: var ( "VOLTA_WRITE_EVENTS_FILE" ) {
18+ Ok ( _) => write_events_file ( events_json. clone ( ) ) ,
19+ Err ( _) => None ,
20+ } ;
21+ if let Some ( ref mut child_process) = spawn_process ( command, tempfile_path) {
22+ if let Some ( ref mut p_stdin) = child_process. stdin . as_mut ( ) {
23+ if let Err ( error) = writeln ! ( p_stdin, "{}" , events_json) {
24+ debug ! ( "Could not write events to executable stdin: {:?}" , error) ;
2225 }
2326 }
2427 }
@@ -60,12 +63,14 @@ fn write_events_file(events_json: String) -> Option<PathBuf> {
6063}
6164
6265// Spawn a child process to receive the events data, setting the path to the events file as an env var
63- fn spawn_process ( command : & str , tempfile_path : PathBuf ) -> Option < Child > {
66+ fn spawn_process ( command : & str , tempfile_path : Option < PathBuf > ) -> Option < Child > {
6467 command. split ( ' ' ) . take ( 1 ) . next ( ) . and_then ( |executable| {
6568 let mut child = create_command ( executable) ;
6669 child. args ( command. split ( ' ' ) . skip ( 1 ) ) ;
6770 child. stdin ( Stdio :: piped ( ) ) ;
68- child. env ( "EVENTS_FILE" , tempfile_path) ;
71+ if let Some ( events_file) = tempfile_path {
72+ child. env ( "EVENTS_FILE" , events_file) ;
73+ }
6974
7075 #[ cfg( not( debug_assertions) ) ]
7176 // Hide stdout and stderr of spawned process in release mode
0 commit comments