I'm not even sure that this is a Perl question. I also think some more specifics would help, but the following may help you...

When a program exits, a return code is made available to the Windows shell. The normal code for "everything worked fine" is "0", zero. Non-zero codes are typically used for error conditions.

My thinking would be that since you want to run a Windows .bat file if this .exe is aborted by CTL-C, i.e. QUIT, then I would start this .exe from a Windows .bat file and check the return value to the shell and then run your "error .bat file" from this "starter" .bat file!

Below I wrote a very simple C program and show a simple .bat file to illustrate how to do this. The C program just echos input lines until you enter "quit". If you enter "quit" the program returns "0" to the shell. However, if you "abort", i.e. force the program to "quit" with CTL-C, it will return a code of "512" to the shell.

So basically, I can tell if the program stopped because of user entering "quit" versus program stopped because of CTL-C.

Type "help start" at your Windows command line for more options on the START command. The /WAIT option is important here! Also I just printed the ERRORLEVEL, I don't know exactly what you have in mind for your "fix-it" .bat file. You will need an IF statement on %ERRORLEVEL%.

*** test.bat *** START /wait echoline ECHO %errorlevel% ****echoline.C **** #include <stdio.h> int main(void) /*simple test program: echoline.C */ { char line[256]; while (printf("%s","Enter Line:"),gets (line) && strcmp(line,"quit") != 0) { printf ("%s\n",line); } }
Oh another point, ERRORLEVEL is NOT an environment variable! ERRORLEVEL is not %ERRORLEVEL%

In reply to Re: While doing force quiting the exe how to run a bat file by Marshall
in thread While doing force quiting the exe how to run a bat file by sudhakar1k

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.