Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

executing a dos program with execl

Posted on 1998-09-03
1
202 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

809 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