-1

I'am trying to start batch file on certain PID, or get PID what program started on. I really have no idea how to do that.

    system("start C:\\testing\\vw.bat");
    Sleep(2000); //1000 = 1s

After this code is executed I need to close "vw.bat", but not close other batch files that are running.

Dokido
  • 15
  • 1
  • 1
  • 5
  • Do you have the restriction that `vw.bat` cannot be altered? Because it's probably a much simpler task if you can just alter that script to start its dependent scripts and then kill itself. – Xirema May 04 '18 at 21:26
  • https://msdn.microsoft.com/en-us/library/ms682623.aspx may get you headed down a fruitful direction. – user4581301 May 04 '18 at 21:35

2 Answers2

0

You can get the PID of your process using system-dependant system calls. For instance, on linux, using pidof. Now, please note using the system() function is not recommended, and other ways of doing what you want exist, like spawning a child process, which will let you kill the process easily.

Magix
  • 4,989
  • 7
  • 26
  • 50
0
PROCESS_INFORMATION pi;
STARTUPINFO si{};
si.cb = sizeof(si);

BOOL success = CreateProcess("start C:\\testing\\vw.bat", NULL, NULL, NULL, TRUE, 0, NULL, "C:\\testing\\", &si, &pi);
if (success)
{
    int pid = pi.dwProcessId;
}
N00byEdge
  • 1,106
  • 7
  • 18
  • While this code may answer the question, it is better to explain how to solve the problem and provide the code for reference. Code-only answers have low utility and are often confusing. – Robert Columbia May 05 '18 at 02:32
  • Sure. But this was a low quality question with no attempt of even googling the answer. Maybe I should have left that as a hint in a comment though. – N00byEdge May 05 '18 at 02:35