Computing.Net > Forums > Unix > Call shell script from C++ program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Call shell script from C++ program

Reply to Message Icon

Name: Dmitri Zaikine
Date: June 21, 2001 at 06:49:48 Pacific
Comment:

Hi
Is anybody knows how to execute shell script from C++ program
Thanks a lot!



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: June 21, 2001 at 08:39:56 Pacific
Reply:

Look up the 'system()' function. I believe that it is fairly standard but am not sure.

Typically, you'd call it by passing a string as the only argument. The string would contain a command that you want to run.

system("erase c:/file.txt");

You may have to include the full path name of the command that you want to run.


0

Response Number 2
Name: NetPortal
Date: June 21, 2001 at 20:21:29 Pacific
Reply:

The common way to do it is to call execl() function (and his analogs). You should run shell with the script you want to execute as a param.
execl("/bin/sh shellscpt", "/bin/sh shellscpt", ....)

And try $man exec


0

Response Number 3
Name: NetPortal
Date: June 22, 2001 at 20:04:03 Pacific
Reply:

Oy, Dima ya oshibsya, vizov delay tak:

execl("/bin/sh", "/bin/sh", "shellscpt")


0

Response Number 4
Name: Dmitri Zaikine
Date: July 2, 2001 at 08:23:34 Pacific
Reply:

Thank you !

#include
main()
{
if (fork() == 0)
execl("/bin/sh","/home/oracle/temp/hello.sh","hello.sh", NULL);
}


0

Response Number 5
Name: Alex
Date: December 13, 2001 at 13:24:12 Pacific
Reply:

a zachem ata proverka?

if (fork() == 0)


0

Related Posts

See More



Response Number 6
Name: Bruno
Date: February 3, 2002 at 00:07:48 Pacific
Reply:

o comando if(fork() == 0) irah pegar o ID do processo corrente e comparar com o ID do processo criado pelo comando fork(), caso essa condicao se verifique, ira executar as instrucoes que estao contidas dentro do escopo de validade do if. (teremos dois processos, mas soh um irah executar - isso eh bastante utilizando para programacao em tempo real, onde se trabalha com escalonamento, prioridade, etc..)


0

Response Number 7
Name: jawad attari
Date: February 9, 2002 at 18:25:19 Pacific
Reply:

hi,

does anybody how to use system() command
for c++ under windows

thankyou


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Call shell script from C++ program

unix commands calling from c program www.computing.net/answers/unix/unix-commands-calling-from-c-program/3363.html

How to call unix script from pl/sql www.computing.net/answers/unix/how-to-call-unix-script-from-plsql/7767.html

Running the shell script from html? www.computing.net/answers/unix/running-the-shell-script-from-html/2406.html