1

I am trying to call a bash script from a Typescript. Tried the following but didn't work, any suggestion?

var script = ##path to the .sh script##
console.log(script)
const { exec } = require("child_process")
exec (script)
 

[UPDATE]

IT seems like it's not calling the .sh script still, not echoing 'works'

enter image description here enter image description here enter image description here enter image description here

1
  • In what way didn't it work? Did it fail to compile? Did you get an error message at runtime? Did your Node process succeed but your script failed to run? (Did you forget to invoke bash explicitly, such that child_process didn't know which actual executable to use?) Commented Oct 2, 2021 at 1:12

1 Answer 1

2

Have you installed @types/node -> npm i --save-dev @types/node If not you should install that first. Then try the following.

You can do it by adding the bash command before the script file path:

import { exec } from 'child_process'

exec('bash path/to/script.sh', (err, stdout, stdrr) => {
  console.log(stdout)
})

or you should set execute permission to bash file with this command:

chmod a+x script.sh

and run it like so:

exec('./path/to/script.sh', (err, stdout, stdrr) => {
  console.log(stdout)
})
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.