Solved

executing a dos program with execl

Posted on 1998-09-03
1
186 Views
Last Modified: 2010-04-10
Hi,
     First i would just like to say i am a beginner with c++ so i know there is probably a better way to do this but can you fix this first and then put any other suggestion at the end.

I have written some small dos programs.  I want to write a small menu system program to execute my programs.  I found the command execl in the help menu but i can't get it to work.  It just says file not found.  It compiles and runs but it just can't find the file, which does exist.  Can you edit this code so it does work.  Thanks (I am using turbo c++)





//FILE: options.cpp
//    Date: Sept 03-98
//Menu system to choose what program to run

#include <iostream.h>
#include <stdio.h>
#include <fstream.h>
#include <ctype.h>
#include <process.h>


void select (char);

void main()
{
      char choice;

      do
      {
            cout << endl << "1) Cir_on";
            cout << endl << "2) Cir_od";
            cout << endl << "q) quit";
            cout << endl << "Enter number of program you wish to run: ";
            cin >> choice;
            select (choice);
      }
      while (toupper (choice) != 'Q');

}

void select (char choice)
{
      char path[80] = "c:\\nc\\anilam\\";
      char argv[40] = "cir_od.exe";
      switch (toupper (choice))
      {
            case '1':
            cout << endl << "executing cir_od...";
            execl(path,argv);
            perror("EXEC:");
            break;

            case '2':
            cout << endl << "executing cir_on";
            break;

            case 'Q':
            cout << endl << "okay bye";
            break;

            default:
            cout << endl << "choose again";
            cin.ignore (80, '\n');

      }
}


0
Comment
Question by:onestar
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1172005
The first param of execl is the full path of the program, the arg (2nd and onwards) parameters are the command line options passed to the program

Change

char path[80] = "c:\\nc\\anilam\\";
char argv[40] = "cir_od.exe";
.etc...
execl(path,argv);

Into

char path[80] = "c:\\nc\\anilam\\cir_od.exe" ;
char argv[40] = "" ;
.etc...
execl(path,argv);


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now