]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/runcmd.c
2 * Run console command and wait for user input
4 * Home page of code is: http://www.smartmontools.org
6 * Copyright (C) 2011 Christian Franke
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 char svnid
[] = "$Id: runcmd.c 4760 2018-08-19 18:45:53Z chrfranke $";
16 int main(int argc
, char **argv
)
18 char * cmd
= GetCommandLineA();
20 STARTUPINFOA si
= { sizeof(si
), };
21 PROCESS_INFORMATION pi
;
26 while (*cmd
&& !(*cmd
== '"' && cmd
[-1] != '\\'))
32 while (*cmd
&& !(*cmd
== ' ' || *cmd
== '\t'))
36 while (*cmd
== ' ' || *cmd
== '\t')
40 printf("%s\n\n", cmd
); fflush(stdout
);
44 printf("Usage: %s COMMAND [ARG ...]\n", argv
[0]);
47 else if (!CreateProcessA((char *)0, cmd
,
48 (SECURITY_ATTRIBUTES
*)0, (SECURITY_ATTRIBUTES
*)0,
49 TRUE
/*inherit*/, 0/*no flags*/, (void *)0, (char *)0, &si
, &pi
)
51 DWORD err
= GetLastError();
52 if (err
== ERROR_FILE_NOT_FOUND
)
53 printf("Command not found\n");
55 printf("CreateProcess() failed with error=%u\n", err
);
59 CloseHandle(pi
.hThread
);
62 WaitForSingleObject(pi
.hProcess
, INFINITE
);
63 GetExitCodeProcess(pi
.hProcess
, &exitcode
);
64 CloseHandle(pi
.hProcess
);
67 printf("\nExitcode: %u (0x%02x)", exitcode
, exitcode
);
70 printf("\nType <return> to exit: "); fflush(stdout
);
71 while (!((key
= getc(stdin
)) == EOF
|| key
== '\n' || key
== '\r'))