473,654 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a shell script from within C++ program

Hi,
I have a shell script which takes three arguments, how can I call this
script from within a C++ program.
I am new to C++ programming and not sure how to accomplish this.
I tried using system() call but could make it work, must be doing
something wrong.
Appreciate any help in this regard.

Thanks,
Juggler

Jul 23 '05 #1
2 3098
Juggler wrote:
I have a shell script which takes three arguments, how can I call this
script from within a C++ program.
I am new to C++ programming and not sure how to accomplish this.
I tried using system() call but could make it work, must be doing
something wrong.


You have to consult your compiler/OS programming manual as to how to
invoke shell scripts using the 'system' function. You probably have to
specify what executable is to process your script, like

system("/bin/sh scriptname");

however, this is off-topic here, since C++ does not define how external
commands are executed via 'system' function.

V
Jul 23 '05 #2
"Juggler" <dy********@yah oo.com> wrote in message
news:a7******** *************** *******@localho st.talkaboutpro gramming.com...
I have a shell script which takes three arguments, how can I call this
script from within a C++ program.
I am new to C++ programming and not sure how to accomplish this.
I tried using system() call but could make it work, must be doing
something wrong.
Probably. Using the system() call is the only way to do it with
the standard C++ library.
Appreciate any help in this regard.


I would recommend asking on a platform-specific forum, as several
aspects of how system() works, and the other techniques you could
use to run the shell script, will depend on your operating system.
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2820
by: David Van Horn | last post by:
As a shell script, the following program works as expected. --------------------------------------- #! /usr/bin/sh echo '<html><? print 1 ?></html>' | php --------------------------------------- However, when run as a CGI script, invoking php causes the php interpreter to load the current file (ie, the sh script), which
3
9939
by: John Bowling | last post by:
I'm creating a routine (not in a browser) to move multiple files on a daily basis to a backup directory. It can be done easily by call shell functions like 'mv file* newdir'. I can't find any reference in the Java tutorial about accessing or using the shell or system other than standard i/o. Does anyone have a clue on how to pass a command to the shell to execute a program? My other option is to write a shell script that calls a few...
11
5027
by: ronan_boisard | last post by:
hi all, I'm trying to call ksh script from python. I have a file (toto.env) with a scirpt looking like: -- begin --- #!/bin/ksh # export TOTO_ENV=/home/toto -- end ---
8
8329
by: Vinod | last post by:
Hi, I have a problem, i am calling an exe from asp program. Its not working fine. When i execute the exe through the dos program directly i get the desired result. My exe will convert files in the folder to encrypted files. But when i call it thru asp program its not working fine. I have tried the following method.
5
1884
by: Juggler | last post by:
Hi, I have a shell script which takes three arguments, how can I call this script from within a C++ program. I am new to C++ programming and not sure how to accomplish this. I tried using system() call but could make it work, must be doing something wrong. Appreciate any help in this regard. Thanks, Juggler
0
393
by: Vladimir Nesterovsky | last post by:
Hello, I'm having a trouble with a Shell.Folder object when I'm trying to use it from a C++ application, but at the same time, the same object works fine from within html script. The effect is that, I cannot put data into a compressed folder in C++, in spite of the fact that all operations succeed. Note: all this have to work under XP and above, because of integrated
11
2721
by: jobs239 | last post by:
Can I use this line inside C program "system(java -jar <jarfilename>)" to run a java program from C? Or do I have to use some JNI interface.?
3
3814
by: George Sakkis | last post by:
I'm trying to figure out why Popen captures the stderr of a specific command when it runs through the shell but not without it. IOW: cmd = if 1: # this captures both stdout and stderr as expected pipe = Popen(' '.join(cmd), shell=True, stderr=PIPE, stdout=PIPE) else: # this captures only stdout pipe = Popen(cmd, shell=False, stderr=PIPE, stdout=PIPE) # this prints the empty string if not run through the shell
5
5078
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then passes these as arguments to a configurable shell script or OS command. I would like for the output generated from the shell script/command shall be displayed in a new javascript window once the form is submitted. Optimally a user should not...
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.