How to run bat file by Delphi

Asked

Viewed 958 times

0

Folks I am trying to run a bat file that is in the same exe folder, however I tried it in several ways and it does not run.

WinExec('startNodeJS.bat',SW_SHOW);

It does not run the bat, this bat is to start the nodejs server, so much so that if I go manual on the bat and double-click it opens the dos and start the nodejs, but by Delphi, it blinks the dos and does nothing, the bat command is :

cd E:\socket
node server.js

I already put the bat in the Past and: socket and also tried to run by Delphi like this :

WinExec('e:\socket\startNodeJS.bat',SW_SHOW);

but also not by Phillip, can someone please help me ?

1 answer

2


Invoke the command interpreter cmd.exe

WinExec('cmd.exe /c "e:\socket\startNodeJS.bat"',SW_SHOW);
cmd.exe /c = executa comando/bat e fecha/close
cmd.exe  /k = executa comando/bat e mantém/keep
  • Thanks for the help, I made the adjustment but still giving error, then I realized that the nodejs was not in the windows path, ai he gave as unrecognized the Node command, after including in the path, worked correctly.

  • @Robinhodemorais Very good your balcony.

  • Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.