Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
How do I use child process spawn to run curl command?

I've been trying to download a HAR file from saucelabs using the exec command, but I get this error when it downloads too much data:

RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stdout maxBuffer length exceeded

I've seen that child_process spawn is used instead for larger files, but I haven't managed to get it to work with all the parameters I am sending. Also I couldn't figure out how to return the downloaded data and store as a variable with spawn. Is anybody able to show me how to use spawn to get the data, and how to save that data into a variable for further processing.

Thanks

async getNetworkRequests (jobId) {
const harFile = await new Promise((resolve, reject) => {
  exec(`curl -u "${process.env.SAUCE_USER}:${process.env.SAUCE_KEY}" --location --compressed --request GET 'https://api.eu-central-1.saucelabs.com/rest/v1/${process.env.SAUCE_USER}/jobs/${jobId}/assets/network.har'`, (error, stdout) => {
    if (error) {
      console.log(`Error message: ${error}`)
      reject(error)
    }
    resolve(stdout)
  })
})
return harFile
}

I've made some progress with spawn, but I am unable to get the data out of the stdout function:

async getNetworkRequests (jobId) {
const spawnProcess = spawn('/bin/sh', ['-c', `curl -u "${process.env.SAUCE_USER}:${process.env.SAUCE_KEY}" --location --compressed --request GET 'https://api.eu-central-1.saucelabs.com/rest/v1/${process.env.SAUCE_USER}/jobs/${jobId}/assets/network.har'`])

const output
spawnProcess.stdout.on('data', data => {
  output = data.toString()
  })
console.log(output) // This returns undefined
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!