473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Invorking a script in c++ code

60
Can any one tell me how I can invorke/call a shell script in a c++ code so that I can I can invorke some shell commands using my c++ code. I am using scientific linux
Nov 28 '06 #1
5 2675
horace1
1,510 Expert 1GB
Can any one tell me how I can invorke/call a shell script in a c++ code so that I can I can invorke some shell commands using my c++ code. I am using scientific linux
you should be able to use the function system() in process.h, e.g. to run a file called script
Expand|Select|Wrap|Line Numbers
  1.     system("sh script");      // invoke a script
  2.  
your parent process is suspended until the script is finished then it is resumed
Nov 28 '06 #2
seforo
60
Thanks, this is what I was looking for
Nov 28 '06 #3
horace1
1,510 Expert 1GB
Thanks, this is what I was looking for
you don't even need to use a script you can run shell programs directly
Expand|Select|Wrap|Line Numbers
  1.     system("ls -l");      // invoke ls
  2.  
if you want the parent to run concurrently with the child process you can use
Expand|Select|Wrap|Line Numbers
  1.     int pid=spawnlp(P_NOWAIT,"ls","ls","-l",NULL);
  2.  
see http://www.python.org/doc/2.3/lib/os-process.html
Nov 28 '06 #4
you don't even need to use a script you can run shell programs directly
Expand|Select|Wrap|Line Numbers
  1.     system("ls -l");      // invoke ls
  2.  
if you want the parent to run concurrently with the child process you can use
Expand|Select|Wrap|Line Numbers
  1.     int pid=spawnlp(P_NOWAIT,"ls","ls","-l",NULL);
  2.  
see http://www.python.org/doc/2.3/lib/os-process.html
I have a question on this,
I am able to run the shell script (getVar.sh) using the system command but I want the string returned by the shell script in my c++ code. I tried using popen but it crashes frequently. Is there anything else I can use?. Please help !!
regards
Feb 1 '07 #5
horace1
1,510 Expert 1GB
I have a question on this,
I am able to run the shell script (getVar.sh) using the system command but I want the string returned by the shell script in my c++ code. I tried using popen but it crashes frequently. Is there anything else I can use?. Please help !!
regards
you could write the output of the script to a file and then open and read that file, e.g.
Expand|Select|Wrap|Line Numbers
  1. system("ls -l > x");      // invoke ls
  2.  
the file listing will be in the file x
Feb 1 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: nobody | last post by:
Hello all, I've searched just about everything and although I can see that other people are having problems, but theirs don't seem to relate, so in a last ditch attempt, my posting! Script...
8
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js...
1
by: Russ | last post by:
I've been trying to get my head around this for 3 days now and it seems like everything I try does not work for one reason or another. I built a test page using the TabStrip and MultiPage controls....
17
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works...
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
10
by: Stefan Weber | last post by:
Hi, I'm trying to access the JavaScript code contained in a <scripttag via its "text" attribute. This works well, if the code is embedded in the HTML page. However, when the code is in an...
47
by: SOLAV | last post by:
This is the only working way to completely hide your JavaScript code from the client just like PHP or ASP code. Here we'll need the help of PHP. Here is the code: index.php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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,...

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.