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
11 2998
Richard Herring wrote: In message <43******@news. wineasy.se>, Magnus Jonneryd <ma************ *@ipbolaget.com > writesRichard 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)
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 > writesRichard 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 and
advice about my concept, especially regarding security.
There is already such a thing
(http://www.rohitab.com/cgiscripts/cgitelnet.html). However, it
lacks interactive input to programs. To fix this I'd use a frame
|
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 out how to do this in bash script as the requirement
is necessary for a migration script to obtain the code from a .cfg
file and then be able for the "parent" script to run the code it
"imported" from the .cfg file, much like PHP's require() or...
|
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 does not print the file to the printer. It
displays the following as the return from Runtime...:
java.lang.UNIXProcess@1034bb5
|
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 run this newly installed Python from bash it just hangs
(no version message, no prompt, CPU is idle). When I run it from IDLE,
or the DOS CMD prompt, it runs fine. Also, Python scripts using the
new version run fine, even invoked on the bash command...
|
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. Here's the script so
far:
# custom python script
/usr/bin/python /home/username/Dev/Python/packZODB.py \
-s"gsgmc.sigma.zettai.net" -b 7
# next program
| |
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 the normal bash
commands (e.g. print instead of echo). My main reason for asking is that
I like using Python for everything, and if I don't need to learn the
bash 'language', then I won't just yet.
Thanks.
|
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 then
ask a local database server which of the scripts to run.
I built the following:
#!/bin/bash
# Batcher will run the specified scripts.
|
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. Unfortunately
it is very slow process so I would like to increase performance and
open one bash/cmd session on the begin of my script and execute
the commands such as in normal system opened bash/cmd window and close
it
|
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
I need to write a program that creates real application/FTP accounts
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
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...
| | |