K
K
kr_ilya2020-03-31 15:50:56
JavaScript
kr_ilya, 2020-03-31 15:50:56

Why doesn't the code work when run with exec()?

I am executing code based on this library. (The repository files are located in the instAPI folder)
Project structure
5e833afaa9b13589198854.png

When the command is executed from the terminal, the
5e833b95b3f03115628507.png
script is successfully executed.
And if you run the same command from the js script, which is located in the tgBot folder using exec

let videoFile = 'file_7.mp4';
let photoFile = 'file_8.jpg';
exec('ts-node /root/autoinst/instAPI/bot/upload.ts videoStory ' + videoFile + ' ' + photoFile, (error, stdout, stderr) => {
      if(error){
        console.log('EXEC ERROR - '+error);
      }else{
        console.log('EXEC OK');
      }
    })


The script does not work and gives errors
5e833c89d27bf069979605.png

What can I do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kr_ilya, 2020-03-31
@kr_ilya

It was necessary to add the parameter cwd (currentWorkDirectory)

const parentDir = path.resolve(process.cwd(), '../instAPI/bot');
exec('ts-node /root/autoinst/instAPI/bot/upload.ts videoStory ' + videoFile + ' ' + photoFile, {cwd: parentDir}, (error, stdout, stderr) => {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question