• C

Open Program when another Closes

Hello, I have 2 programs written in C, and I want one to open when the other closes.  Can anyone help me out?
People_CodeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rishiskCommented:
Though I'm not sure of what you want to achieve, you can write a small shell script (in Unix) or a batch file in (Windows) with program B called after program A. Since the order of execution is sequential, you'll get what you want.

0
People_CodeAuthor Commented:
oh man, I never even though of that.  Do you know how to insert the batch file?
0
rishiskCommented:
If you are using windows, try the following:

Create a file called exec_prgs.bat (through notepad) in which you'll type the following (assuming that a.exe and b.exe are the programs to be executed in the order:

a.exe
b.exe

That's it.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

People_CodeAuthor Commented:
Ok but, how do you put the bat into the C code?
0
rishiskCommented:
You don't need to put the batch file into code. Please send in the C program code. Probably, I can explain you better.
0
People_CodeAuthor Commented:
where to?
0
rishiskCommented:
Paste it here.
0
People_CodeAuthor Commented:
This is program 1.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<conio.h>
#define SMALL_STR_LEN 80
#define LARGE_STR_LEN 1024


char name[SMALL_STR_LEN],sel[SMALL_STR_LEN],steal[SMALL_STR_LEN],account[SMALL_STR_LEN],email[SMALL_STR_LEN],web[SMALL_STR_LEN],html_code[LARGE_STR_LEN],crash[SMALL_STR_LEN];
char url[]="//";
int selection,prog_exit;
char *stripweb;

void create_menu(void);
char get_string(char* get_var, int get_len);

int main()
{
  system("color A");

  printf("\n                                 People Code\n");
  printf("\n                                 Version 1.0");
printf("\n           ........ ........ .......... ........ ...       ........");
printf("\n           : .... : : .....: : ...... : : .... : : :       : .....:");
printf("\n           : :  : : : :      : :    : : : :  : : : :       : : ");
printf("\n           : :..: : : :...   : :    : : : :..: : : :       : :...");
printf("\n           : .....: : ...:   : :    : : : .....: : :       : ...:");
printf("\n           : :      : :      : :    : : : :      : :       : :");
printf("\n           : :      : :      : :    : : : :      : :       : :");
printf("\n           : :      : :..... : :....: : : :      : :...... : :.....");
printf("\n           :.:      :......: :........: :.:      :.......: :......:");
printf("\n                    ......... .......... .....    ........");
printf("\n                    : ......: : ...... : : .. :   : .....:");
printf("\n                    : :       : :    : : : : : :  : :");
printf("\n                    : :       : :    : : : :  : : : :...");
printf("\n                    : :       : :    : : : :  : : : ...:");
printf("\n                    : :       : :    : : : :  : : : :");
printf("\n                    : :       : :    : : : : : :  : :");
printf("\nWritten by:         : :...... : :....: : : :. :   : :.....");
printf("\nTyler McCormack     :.......: :........: :...:    :......:");


  printf("\n\n                          Press enter to continue\n");

  getch();


    while(1) {
    create_menu();
    get_string(sel,SMALL_STR_LEN);
    selection = atoi(sel);
    if (selection > 6 || selection < 1) {
      printf("\n\nInvalid Selection, pick somthing from the menu.\n\n");
    }
    else {
      switch(selection) {

      case 1:
      prog_exit=1;
      printf("\nWhat is the ip address of the computer you want to steal files from?\n\n",steal);
      get_string(steal,SMALL_STR_LEN);
      if('\0'== steal[0]) {
        printf("\n\nNull value not allowed\n\n");
        break;
      }
      else {
        printf("\n\nConnecting to %s...\n",steal);
      sleep(5000);
      printf("\n\nConnection Successful\n");
      sleep(1000);
      printf("\n\nWhat is the name of the file you want to steal?\n",name);
      get_string(steal,SMALL_STR_LEN);
      printf("\nSearching for %s...\n\n",steal);
      sleep(6000);
      printf("\nSorry, no %s was found on this computer.\n\n",steal);


      break;

      }
      case 2:
      prog_exit=1;
      printf("What is the name of the Yahoo/Hotmail account you wish to crack? ");
      get_string(account,SMALL_STR_LEN);
      if('\0' == account[0]) {
        printf("\n\nNull value not allowed\n\n");
        break;
      }
      else {
        printf("Is this a (Y)ahoo or (H)otmail account? ");
        get_string(email,SMALL_STR_LEN);
        if(strcmp(email,"Y") == 0 || strcmp(email,"y") == 0) {
          printf("\n\nAttempting to Access %s@yahoo.com...please wait\n",account);
          sleep(5000);
          printf("\n\nConnection to 66.218.71.198\n");
          sleep(3000);
          printf("\n\nConnection Successful\n\n\nAttempting to access list of emails for %s@yahoo.com\n",account);
          sleep(3000);
          printf("\n\nNo E-mails currently found for this user, please try again later\n\n");
          break;
        }
        else if(strcmp(email,"H") == 0 || strcmp(email,"h") == 0) {
          printf("\n\nAttempting to Access %s@hotmail.com...please wait...\n",account);
          sleep(5000);
          printf("\n\nConnection TO 64.4.44.7...\n");
          sleep(3000);
          printf("\n\nConnection Successful\n\n\nAttemping to access list of emails for %s@hotmail.com\n",account);
          sleep(3000);
          printf("\n\nNo E-mails currently found for this user, please try again later.\n\n");
          break;
        }
        else {
          printf("\n\nYou have a choice, Yahoo (Y), or Hotmail (H).  Pick one.\n\n");
          break;
        }
      }
      case 3:
      prog_exit=1;
      printf("\n\nWhat is the website URL that you wish to deface\n");
      get_string(web,SMALL_STR_LEN);
      if('\0' == web[0]) {
        printf("\n\nNull Value Not Allowed\n\n");
        break;
      }
      else {
        stripweb = strstr(web,url);
        if(stripweb) {
          stripweb += strlen(url);
          printf("\n\nAttempting to connect to the url: %s\n",stripweb);
        }
        else {
          printf("\n\nAttempting to connect to the url: %s\n",web);
        }
      }
      sleep(2000);
      printf("\n\nConnection Established\n");
      printf("\n\nEnter the HTML you want for this index file on one line\n");
      get_string(html_code,LARGE_STR_LEN);
      if('\0'== html_code[0])  {
        printf("\n\nNull Value not allowed\n\n");
        break;
      }
      else {
        printf("\n\nAdding the following code to the index file: %s\n",html_code);
        if(strlen(html_code) < 50) {
          sleep(2000);
        }
        else if(strlen(html_code) > 50 && strlen(html_code) < 200) {
          sleep(2000);
        }
        else {
          sleep(2000);
        }
        printf("\n\nUPLOAD COMPLETE! Disconnecting from server\n\n");
        sleep(1000);
        break;
      }

      case 4:
      prog_exit=1;
      printf("\n\nWhat is the ip adress of the pc you would like to crash?\n\n");
      get_string(crash,SMALL_STR_LEN);
      if('\0' == crash[0]) {
        printf("\n\nNull Value Not Allowed\n\n");
        break;
      }
      else {
        printf("\n\nConnection to %s...\n\n",crash);
        sleep(5000);
        printf("\n\nConnection Complete!\n\n");
        sleep(1000);
        printf("\n\nDeleting Windows Explorer...\n\n");
        sleep(4000);
        printf("\n\nExplorer deleted!  Computer Crashed!!!\n\n");
        sleep(1000);
        break;
        }
        case 5:

      if(prog_exit == 0) {
      printf("\n\nThank you using my program that doesn't do anything. If this program did what it says it does, I wouldn't have written it.  Hacking isn't about defacing        websites and cracking email accounts.  It's about learning.  Don't ever deface  websites or crash computers, or anything like that.  All that will do for you   is get you a hefty fine and lots of jail time.%s\n\n",name); {
      system("PAUSE");

      }
      if (strlen(name) <50) {
      }
      }
      return(0);
      }
    }
  }
  return 0;
}
FILE *fp;

if ((fp = fopen("myfile", "r")) ==NULL){
  printf("Error opening file\n");
  exit(1);
}

void create_menu(void) {
  printf("\nPeople Code: MENU\n\n"
       "1) Steal files\n"
       "2) Crack a Yahoo or Hotmail account\n"
     "3) Take down a website\n"
     "4) Crash a PC\n"
     "5) Quit People Code\n\n"
       "SELECTION: ");
}

char get_string(char* get_var, int get_len) {
  char *termcheck;
  memset(get_var, (int)'\0', get_len);
  fgets(get_var,get_len,stdin);
  termcheck = strchr(get_var,'\n');
  if(termcheck != NULL) *termcheck='\0';
  return 15;
}


I want this program (or some kind of pop-up) to come up when you exit program 1.

#include<stdio.h>

int main () {
system("color A");
  printf("\n\nThank you using my program that doesn't do anything. If this program did what it says it does, I wouldn't have written it.  Hacking isn't about defacing        websites and cracking email accounts.  It's about learning.  Don't ever deface   websites or crash a computer, or anything like that.  All that will do for you is get you a hefty fine and lots of jail time.\n\n"); {
  system("PAUSE");
}
  return(0);
}
0
rishiskCommented:
The program 2 is already part of the first program. So why do you want print the message again. Anyway, if that is what you want, compile both programs, then create a text file as mentioned earlier, with the name of the first executable in the first line and name of the second executable in the next line and name it with a .bat extension. Once the batch file is created, in the command prompt, change directory to where you have created the .bat file and type the name of the batch file. This batch file should run the first program. If the user chooses the option 5, the first program will exit. Now the batch file takes the control and moves to the next line and executes the second program, which prints the message.
0
People_CodeAuthor Commented:
well, whenever i exit the program, that message does not show up and i want it to.  any suggestions?
0
rishiskCommented:
Can you paste the exact command you typed in. Make sure both the executbles, the batch file are placed in the same directory.
0
sunnycoderCommented:
suppose you want to launch programB when programA is about to exit.
system() function is used to launch program from inside another program
system ("path_to_program_B");
statement when inserted in program A, will launch programB
be warned, programA will not proceed further from this point until programB finishes and returns. If that behaviour is not desirable, then use fork() followed by exec() on *nix machine and CreateProcess() on windows.

Since you talked about launching on exit, you can put all the actions you want to be performed at exit in a function and register that function using atexit(). This registered function would be invoked when your program is about to exit.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.