Answer the question
In order to leave comments, you need to log in
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
When the command is executed from the terminal, the
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');
}
})
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question