473,401 Members | 2,146 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,401 software developers and data experts.

Bash and C++, friends?

Hi, I'm planning on writing a program that interactively is fed input via a
shell (bash). I also want to be able to write a shell script that executes
various commands related to my program. In short i want to provide input to
a program using some (or all) of the functionality found in bash.

It's mainly the format of the file I'm having trouble with. I wanted to be
able to write something like this:
#!/bin/bash

for x in xs
do
myprog.method(x)
done

How do i call myprog from a bash script (myprog is executing and reacting to
the input)?

Hopefully I've been able to convey my message.

Thanks in advance!

--
(Should insert humorous quotation here)
Aug 13 '05 #1
11 2974
Magnus Jonneryd wrote:
Hi, I'm planning on writing a program that interactively is fed input
via a shell (bash). I also want to be able to write a shell script
that executes various commands related to my program. In short i want
to provide input to a program using some (or all) of the
functionality found in bash.

It's mainly the format of the file I'm having trouble with. I wanted
to be able to write something like this:
#!/bin/bash

for x in xs
do
myprog.method(x)
done

How do i call myprog from a bash script (myprog is executing and
reacting to the input)?


I think you need to look at (a) how arguments are passed to your
programs and for that see the arguments to 'main' function and (b)
look at some primitive expression parsing.

I speculate that it should be possible to write a script to call
your program similarly to

do
myprog "method" $x
done

in which "method" will indicate which method to call and $x will
expand into something that can be internally converted into values
to pass to that method (function).

V
Aug 13 '05 #2
Victor Bazarov wrote:
Magnus Jonneryd wrote:
Hi, I'm planning on writing a program that interactively is fed input
via a shell (bash). I also want to be able to write a shell script
that executes various commands related to my program. In short i want
to provide input to a program using some (or all) of the
functionality found in bash.

It's mainly the format of the file I'm having trouble with. I wanted
to be able to write something like this:
#!/bin/bash

for x in xs
do
myprog.method(x)
done

How do i call myprog from a bash script (myprog is executing and
reacting to the input)?


I think you need to look at
(a) how arguments are passed to your programs and for that see the
arguments to 'main' function


Sure, but it's still a matter of how. How do I, in the bash script, specify
that it is myprog that should receive the input? To simply provide input at
the start of execution via the commandline isn't enough. I need to be able
to provide arguments during the programs entire execution and I want to use
some bashscripts since I don't want to invent or rather implement a new
script language.

Grateful, for input.

--
(Should insert humorous quotation here)
Aug 13 '05 #3
On Sat, 13 Aug 2005 17:44:26 +0200, Magnus Jonneryd wrote:
Hi, I'm planning on writing a program that interactively is fed input via a
shell (bash). I also want to be able to write a shell script that executes
various commands related to my program. In short i want to provide input to
a program using some (or all) of the functionality found in bash.

It's mainly the format of the file I'm having trouble with. I wanted to be
able to write something like this:
#!/bin/bash

for x in xs
do
myprog.method(x)
done

How do i call myprog from a bash script (myprog is executing and reacting to
the input)?

Hopefully I've been able to convey my message.

Thanks in advance!


Well, there's no way to directly call a method from a shell script. How
you go about doing this indirectly depends on what you want. As someone
else mentioned, one way is just command line arguments. If you need the
functions to be called successively during one run of myprog, probably the
best way is to make myprog be kind of a shell itself.

The way you do this is, in the main() of myprog, have a loop that reads a
line from standard input (gets(), cin.getline()) and call the associated
function with the given arguments. Then, in a shell script, you can do
something like:

(
echo init_method
for x in xs; do
echo method $x;
done
echo other_methods
) | myprog

You could debug this by taking out the "| myprog" part, in which case the
script will print to stdout what it would have given to your program.
You can also test your program by just running it on its own and typing in
your functions manually.

--
Tom Felker, <tf******@uiuc.edu>
<http://vlevel.sourceforge.net> - Stop fiddling with the volume knob.

Code is speech!

Aug 15 '05 #4
Tom Felker wrote:
On Sat, 13 Aug 2005 17:44:26 +0200, Magnus Jonneryd wrote:
Hi, I'm planning on writing a program that interactively is fed input via
a shell (bash). I also want to be able to write a shell script that
executes various commands related to my program. In short i want to
provide input to a program using some (or all) of the functionality found
in bash.

It's mainly the format of the file I'm having trouble with. I wanted to
be able to write something like this:
#!/bin/bash

for x in xs
do
myprog.method(x)
done

How do i call myprog from a bash script (myprog is executing and reacting
to the input)?

Hopefully I've been able to convey my message.

Thanks in advance!


Well, there's no way to directly call a method from a shell script. How
you go about doing this indirectly depends on what you want. As someone
else mentioned, one way is just command line arguments. If you need the
functions to be called successively during one run of myprog, probably the
best way is to make myprog be kind of a shell itself.

The way you do this is, in the main() of myprog, have a loop that reads a
line from standard input (gets(), cin.getline()) and call the associated
function with the given arguments. Then, in a shell script, you can do
something like:

(
echo init_method
for x in xs; do
echo method $x;
done
echo other_methods
) | myprog

You could debug this by taking out the "| myprog" part, in which case the
script will print to stdout what it would have given to your program.
You can also test your program by just running it on its own and typing in
your functions manually.

Ok, I thought that might be the case. Was hoping to avoid parsing but it
seems unavoidable. Well, well, thanks anyway.

I realize this might be the wrong forum, but I was thinking that it might be
possible to use Python instead of shell-scripts, any thoughts?
--
(Should insert humorous quotation here)
Aug 15 '05 #5
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Tom Felker wrote:
On Sat, 13 Aug 2005 17:44:26 +0200, Magnus Jonneryd wrote:
Hi, I'm planning on writing a program that interactively is fed input via
a shell (bash). I also want to be able to write a shell script that
executes various commands related to my program. In short i want to
provide input to a program using some (or all) of the functionality found
in bash.

It's mainly the format of the file I'm having trouble with. I wanted to
be able to write something like this:
#!/bin/bash

for x in xs
do
myprog.method(x)
done

How do i call myprog from a bash script (myprog is executing and reacting
to the input)?

Hopefully I've been able to convey my message.

Thanks in advance!


Well, there's no way to directly call a method from a shell script. How
you go about doing this indirectly depends on what you want. As someone
else mentioned, one way is just command line arguments. If you need the
functions to be called successively during one run of myprog, probably the
best way is to make myprog be kind of a shell itself.

The way you do this is, in the main() of myprog, have a loop that reads a
line from standard input (gets(), cin.getline()) and call the associated
function with the given arguments. Then, in a shell script, you can do
something like:

(
echo init_method
for x in xs; do
echo method $x;
done
echo other_methods
) | myprog

You could debug this by taking out the "| myprog" part, in which case the
script will print to stdout what it would have given to your program.
You can also test your program by just running it on its own and typing in
your functions manually.

Ok, I thought that might be the case. Was hoping to avoid parsing but it
seems unavoidable. Well, well, thanks anyway.

I realize this might be the wrong forum, but I was thinking that it might be
possible to use Python instead of shell-scripts, any thoughts?


It sounds as though you're looking for a scripting language with a C++
(or C?) API so that you can embed a script interpreter within your
application and have it execute callbacks into your code when it finds
appropriate commands in the script. I don't know enough details to make
recommendations, but Python, Perl, Rexx, Ruby and similar script
interpreters might be possible candidates.

--
Richard Herring
Aug 16 '05 #6
Richard Herring wrote:
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Tom Felker wrote:
On Sat, 13 Aug 2005 17:44:26 +0200, Magnus Jonneryd wrote:

Hi, I'm planning on writing a program that interactively is fed input
via a shell (bash). I also want to be able to write a shell script that
executes various commands related to my program. In short i want to
provide input to a program using some (or all) of the functionality
found in bash.

It's mainly the format of the file I'm having trouble with. I wanted to
be able to write something like this:
#!/bin/bash

for x in xs
do
myprog.method(x)
done

How do i call myprog from a bash script (myprog is executing and
reacting to the input)?

Hopefully I've been able to convey my message.

Thanks in advance!

Well, there's no way to directly call a method from a shell script. How
you go about doing this indirectly depends on what you want. As someone
else mentioned, one way is just command line arguments. If you need the
functions to be called successively during one run of myprog, probably
the best way is to make myprog be kind of a shell itself.

The way you do this is, in the main() of myprog, have a loop that reads
a line from standard input (gets(), cin.getline()) and call the
associated
function with the given arguments. Then, in a shell script, you can do
something like:

(
echo init_method
for x in xs; do
echo method $x;
done
echo other_methods
) | myprog

You could debug this by taking out the "| myprog" part, in which case
the script will print to stdout what it would have given to your
program. You can also test your program by just running it on its own
and typing in your functions manually.

Ok, I thought that might be the case. Was hoping to avoid parsing but it
seems unavoidable. Well, well, thanks anyway.

I realize this might be the wrong forum, but I was thinking that it might
be possible to use Python instead of shell-scripts, any thoughts?


It sounds as though you're looking for a scripting language with a C++
(or C?) API so that you can embed a script interpreter within your
application and have it execute callbacks into your code when it finds
appropriate commands in the script. I don't know enough details to make
recommendations, but Python, Perl, Rexx, Ruby and similar script
interpreters might be possible candidates.


I was thinking along those lines and I've discovered the module/library
BOOST. Can someone that had some experience using it give me a quick review
i.e do you recommend it or not?

--
(Should insert humorous quotation here)
Aug 16 '05 #7
Hi,

Not BOOST thing. But, have you checked CINT for your scripting ?
CINT is a C/C++ interpreter. You can write your script by C/C++ that
links to your C/C++ program. Please refer
http://root.cern.ch/root/Cint.html for more details. Its not 100%
complete C/C++ interpreter though.............

Hajime

Aug 16 '05 #8
hajime wrote:
Hi,

Not BOOST thing. But, have you checked CINT for your scripting ?
CINT is a C/C++ interpreter. You can write your script by C/C++ that
links to your C/C++ program. Please refer
http://root.cern.ch/root/Cint.html for more details. Its not 100%
complete C/C++ interpreter though.............

Hajime


Sounds really interesting, thanks.
--
(Should insert humorous quotation here)
Aug 16 '05 #9
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Richard Herring wrote:
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Tom Felker wrote:

On Sat, 13 Aug 2005 17:44:26 +0200, Magnus Jonneryd wrote:

> Hi, I'm planning on writing a program that interactively is fed input
> via a shell (bash). I also want to be able to write a shell script that
> executes various commands related to my program. In short i want to
> provide input to a program using some (or all) of the functionality
> found in bash.
>
> It's mainly the format of the file I'm having trouble with. I wanted to
> be able to write something like this:
> #!/bin/bash
>
> for x in xs
> do
> myprog.method(x)
> done
>
> How do i call myprog from a bash script (myprog is executing and
> reacting to the input)?
>
> Hopefully I've been able to convey my message.
>
> Thanks in advance!

Well, there's no way to directly call a method from a shell script. How
you go about doing this indirectly depends on what you want. As someone
else mentioned, one way is just command line arguments. If you need the
functions to be called successively during one run of myprog, probably
the best way is to make myprog be kind of a shell itself.

The way you do this is, in the main() of myprog, have a loop that reads
a line from standard input (gets(), cin.getline()) and call the
associated
function with the given arguments. Then, in a shell script, you can do
something like:

(
echo init_method
for x in xs; do
echo method $x;
done
echo other_methods
) | myprog

You could debug this by taking out the "| myprog" part, in which case
the script will print to stdout what it would have given to your
program. You can also test your program by just running it on its own
and typing in your functions manually.

Ok, I thought that might be the case. Was hoping to avoid parsing but it
seems unavoidable. Well, well, thanks anyway.

I realize this might be the wrong forum, but I was thinking that it might
be possible to use Python instead of shell-scripts, any thoughts?


It sounds as though you're looking for a scripting language with a C++
(or C?) API so that you can embed a script interpreter within your
application and have it execute callbacks into your code when it finds
appropriate commands in the script. I don't know enough details to make
recommendations, but Python, Perl, Rexx, Ruby and similar script
interpreters might be possible candidates.


I was thinking along those lines and I've discovered the module/library
BOOST. Can someone that had some experience using it give me a quick review
i.e do you recommend it or not?

Boost is highly recommended - for what it does, but it's not what you're
looking for here. It's not a module but a collection of relatively
low-level algorithms and utilities. There are parts which would
certainly help if you wanted to write your own parser, but that would be
a *lot* of work compared with slotting in a ready-made interpreter.

--
Richard Herring
Aug 17 '05 #10
Richard Herring wrote:
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Richard Herring wrote:
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Tom Felker wrote:

> On Sat, 13 Aug 2005 17:44:26 +0200, Magnus Jonneryd wrote:
>
>> Hi, I'm planning on writing a program that interactively is fed input
>> via a shell (bash). I also want to be able to write a shell script
>> that executes various commands related to my program. In short i want
>> to provide input to a program using some (or all) of the
>> functionality found in bash.
>>
>> It's mainly the format of the file I'm having trouble with. I wanted
>> to be able to write something like this:
>> #!/bin/bash
>>
>> for x in xs
>> do
>> myprog.method(x)
>> done
>>
>> How do i call myprog from a bash script (myprog is executing and
>> reacting to the input)?
>>
>> Hopefully I've been able to convey my message.
>>
>> Thanks in advance!
>
> Well, there's no way to directly call a method from a shell script.
> How
> you go about doing this indirectly depends on what you want. As
> someone
> else mentioned, one way is just command line arguments. If you need
> the functions to be called successively during one run of myprog,
> probably the best way is to make myprog be kind of a shell itself.
>
> The way you do this is, in the main() of myprog, have a loop that
> reads a line from standard input (gets(), cin.getline()) and call the
> associated
> function with the given arguments. Then, in a shell script, you can
> do something like:
>
> (
> echo init_method
> for x in xs; do
> echo method $x;
> done
> echo other_methods
> ) | myprog
>
> You could debug this by taking out the "| myprog" part, in which case
> the script will print to stdout what it would have given to your
> program. You can also test your program by just running it on its own
> and typing in your functions manually.
>
Ok, I thought that might be the case. Was hoping to avoid parsing but it
seems unavoidable. Well, well, thanks anyway.

I realize this might be the wrong forum, but I was thinking that it
might be possible to use Python instead of shell-scripts, any thoughts?

It sounds as though you're looking for a scripting language with a C++
(or C?) API so that you can embed a script interpreter within your
application and have it execute callbacks into your code when it finds
appropriate commands in the script. I don't know enough details to make
recommendations, but Python, Perl, Rexx, Ruby and similar script
interpreters might be possible candidates.


I was thinking along those lines and I've discovered the module/library
BOOST. Can someone that had some experience using it give me a quick
review i.e do you recommend it or not?

Boost is highly recommended - for what it does, but it's not what you're
looking for here. It's not a module but a collection of relatively
low-level algorithms and utilities. There are parts which would
certainly help if you wanted to write your own parser, but that would be
a *lot* of work compared with slotting in a ready-made interpreter.


Must have misinterpreted the info, sorry. Do you have an opinion about cint
or some other interpreter (preferably for C/C++ or Python)?
--
(Should insert humorous quotation here)
Aug 18 '05 #11
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Richard Herring wrote:
In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
Richard Herring wrote:

In message <43******@news.wineasy.se>, Magnus Jonneryd
<ma*************@ipbolaget.com> writes
>Tom Felker wrote:
>
>> On Sat, 13 Aug 2005 17:44:26 +0200, Magnus Jonneryd wrote:
>>
>>> Hi, I'm planning on writing a program that interactively is fed input
>>> via a shell (bash). I also want to be able to write a shell script
>>> that executes various commands related to my program. In short i want
>>> to provide input to a program using some (or all) of the
>>> functionality found in bash.
>>>
>>> It's mainly the format of the file I'm having trouble with. I wanted
>>> to be able to write something like this:
>>> #!/bin/bash
>>>
>>> for x in xs
>>> do
>>> myprog.method(x)
>>> done
>>>
>>> How do i call myprog from a bash script (myprog is executing and
>>> reacting to the input)?
>>>
>>> Hopefully I've been able to convey my message.
>>>
>>> Thanks in advance!
>>
>> Well, there's no way to directly call a method from a shell script.
>> How
>> you go about doing this indirectly depends on what you want. As
>> someone
>> else mentioned, one way is just command line arguments. If you need
>> the functions to be called successively during one run of myprog,
>> probably the best way is to make myprog be kind of a shell itself.
>>
>> The way you do this is, in the main() of myprog, have a loop that
>> reads a line from standard input (gets(), cin.getline()) and call the
>> associated
>> function with the given arguments. Then, in a shell script, you can
>> do something like:
>>
>> (
>> echo init_method
>> for x in xs; do
>> echo method $x;
>> done
>> echo other_methods
>> ) | myprog
>>
>> You could debug this by taking out the "| myprog" part, in which case
>> the script will print to stdout what it would have given to your
>> program. You can also test your program by just running it on its own
>> and typing in your functions manually.
>>
>Ok, I thought that might be the case. Was hoping to avoid parsing but it
>seems unavoidable. Well, well, thanks anyway.
>
>I realize this might be the wrong forum, but I was thinking that it
>might be possible to use Python instead of shell-scripts, any thoughts?

It sounds as though you're looking for a scripting language with a C++
(or C?) API so that you can embed a script interpreter within your
application and have it execute callbacks into your code when it finds
appropriate commands in the script. I don't know enough details to make
recommendations, but Python, Perl, Rexx, Ruby and similar script
interpreters might be possible candidates.
I was thinking along those lines and I've discovered the module/library
BOOST. Can someone that had some experience using it give me a quick
review i.e do you recommend it or not?

Boost is highly recommended - for what it does, but it's not what you're
looking for here. It's not a module but a collection of relatively
low-level algorithms and utilities. There are parts which would
certainly help if you wanted to write your own parser, but that would be
a *lot* of work compared with slotting in a ready-made interpreter.


Must have misinterpreted the info, sorry. Do you have an opinion about cint
or some other interpreter (preferably for C/C++ or Python)?

Sorry, I've no experience of any of them. Anyone else?

--
Richard Herring
Aug 18 '05 #12

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

Similar topics

3
by: Bernhard Kuemel | last post by:
Hi! To relief the problems of accessing a unix machine from behind a restrictive firewall or from an internet cafe I started to make a PHP web interface to bash. I'd like to hear your opinions...
5
by: Phil Powell | last post by:
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure...
3
by: John Bowling | last post by:
I have a java (2.0) program with the following lines: String cmdArray1 = {"lp", "-d", "hp4m", "MyFile"}; System.out.println(Runtime.getRuntime().exec(cmdArray1)); It compliles properly, but...
2
by: Eric Woudenberg | last post by:
I just installed a Python 2.3.4 Windows binary on a friend's WinXP machine (because the latest Cygwin-provided Python 2.3 build leaves out the winsound module for some reason). When I try and...
4
by: Tom Purl | last post by:
I just wrote a Python script that is going to be called from bash script. If the Python script fails, I want the bash script to also stop running. Unfortunately, I can't seem to get that to work. ...
16
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
6
by: Ishpeck | last post by:
I'm using Python to automate testing software for my company. I wanted the computers in my testing lab to automatically fetch the latest version of the python scripts from a CVS repository and...
4
by: melmack3 | last post by:
Hello My PHP script executes many bash/cmd commands. Functions like "exec()" or "system()" cause that new bash/cmd session is started, the command is executed and the session is closed....
6
by: Frantisek Malina | last post by:
What is the best way to do the regular bash commands in native python? - create directory - create file - make a symlink - copy a file to another directory - move a file - set permissions ...
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.