0

I executed a command on the system and want to see the results of the command with out the stdout properties coming in my way `

const prompt = require('prompt-sync')({ sigint: true });
const { exec } = require('child_process');
const { stdout } = require('process');
const pathToElevate = Number(prompt('1- suid -2 binary root 3- cap: '))
const userPassword = prompt('Please put the user password(optinal): ')


console.log(stdout)

if (pathToElevate === 1) {
    var commandOutput = exec('ls', (error, stdout, stderr) => {
        if (error) {
            console.log(`error ${error.message}`)
            return;
        } if (stderr) {
            console.log(`stderr ${stderr.message}`)
            return;
        }
        return console.log(stdout) // here is my problem, I want to parse stdout to show the results of ls
    })
    console.log(commandOutput)

`

I tried searching on google but didn't find any thing and here is the result `

<ref *1> ChildProcess {
  _events: [Object: null prototype] {
    close: [Function: exithandler],
    error: [Function: errorhandler]
  },
  _eventsCount: 2,
  _maxListeners: undefined,
  _closesNeeded: 3,
  _closesGot: 0,
  connected: false,
  signalCode: null,
  exitCode: null,
  killed: false,
  spawnfile: '/bin/sh',
  _handle: Process {
    onexit: [Function (anonymous)],
    pid: 8058,
    [Symbol(owner_symbol)]: [Circular *1]
  },
  spawnargs: [ '/bin/sh', '-c', 'ls' ],
  pid: 8058,...

a.out
index.js
node_modules
package.json
package-lock.json

I only want the last bit

4
  • stdout.on("data", (d) => { console.log(d); } Commented Dec 7, 2022 at 13:47
  • can you explain a little more? , cause this is my first time working with stdout/in/err Commented Dec 7, 2022 at 15:22
  • More information in the docs -> nodejs.org/api/child_process.html#child-process Commented Dec 7, 2022 at 15:26
  • thanks mate I just had to delete the console.log() Commented Dec 7, 2022 at 18:38

1 Answer 1

1

Your code works OK for me. just comment out the console.log(stdout) in line 8 and console.log(commandOutPut) in line 21 and you are good to go.. screenshot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.