]>
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://smartmontools.sourceforge.net
6 * Copyright (C) 2011 Christian Franke <smartmontools-support@lists.sourceforge.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * You should have received a copy of the GNU General Public License
14 * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
18 char svnid
[] = "$Id: runcmd.c 3453 2011-10-16 12:45:27Z chrfranke $";
23 int main(int argc
, char **argv
)
25 char * cmd
= GetCommandLineA();
27 STARTUPINFOA si
= { sizeof(si
), };
28 PROCESS_INFORMATION pi
;
33 while (*cmd
&& !(*cmd
== '"' && cmd
[-1] != '\\'))
39 while (*cmd
&& !(*cmd
== ' ' || *cmd
== '\t'))
43 while (*cmd
== ' ' || *cmd
== '\t')
47 printf("%s\n\n", cmd
); fflush(stdout
);
51 printf("Usage: %s COMMAND [ARG ...]\n", argv
[0]);
54 else if (!CreateProcessA((char *)0, cmd
,
55 (SECURITY_ATTRIBUTES
*)0, (SECURITY_ATTRIBUTES
*)0,
56 TRUE
/*inherit*/, 0/*no flags*/, (void *)0, (char *)0, &si
, &pi
)
58 DWORD err
= GetLastError();
59 if (err
== ERROR_FILE_NOT_FOUND
)
60 printf("Command not found\n");
62 printf("CreateProcess() failed with error=%u\n", err
);
66 CloseHandle(pi
.hThread
);
69 WaitForSingleObject(pi
.hProcess
, INFINITE
);
70 GetExitCodeProcess(pi
.hProcess
, &exitcode
);
71 CloseHandle(pi
.hProcess
);
74 printf("\nExitcode: %u (0x%02x)", exitcode
, exitcode
);
77 printf("\nType <return> to exit: "); fflush(stdout
);
78 while (!((key
= getc(stdin
)) == EOF
|| key
== '\n' || key
== '\r'))