Code Monkey home page Code Monkey logo

Comments (3)

gaborcsardi avatar gaborcsardi commented on July 30, 2024

Three tips:

  1. if you know that you can have long lines, you need to use read_output() instead of read_output_lines().
  2. read_output() can always return less output than requested.
  3. you need to call $poll_io() before reading, even if you call it with no waiting time: $poll_io(0).

from processx.

chwpearse avatar chwpearse commented on July 30, 2024

Ah thanks for that. For anyone who hits this problem in the future here's what I did:

proc_read_long_singleline <- function(proc, wait = 100, timeout = 5000){
  my_proc$poll_io(wait)
  counter <- 1
  output_lines_res <- proc$read_output_lines(1)
  output_res <- c()
  
  while(length(output_lines_res) == 0 & counter*wait <= timeout){
    output_res <- proc$read_output() %>% append(output_res, .)
    proc$poll_io(wait)
    counter <- counter + 1
    output_lines_res <- proc$read_output_lines(1) %>% append(output_lines_res, .)
  }
  
  res_output <- paste0(output_res, collapse = '') %>% paste0(output_lines_res)
}

if(exists('my_proc')){my_proc$kill()}
my_proc <- process$new(cmd_file, stdin = '|', stdout = '|', stderr = '|')
my_proc$write_input('\n')

read_chars <- my_proc %>% proc_read_long_singleline()

from processx.

gaborcsardi avatar gaborcsardi commented on July 30, 2024

I think this is documented, but I'll keep this issue open until we improve the documentation.

from processx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.