Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > system() commands

Reply
Thread Tools

system() commands

 
 
Kim Gardiner CS2003
Guest
Posts: n/a
 
      01-30-2007
Hi,
I have been using perl to launch Prolog via the system("swipl");
command. This has worked fine so far. However, when I try to issue
commands to Prolog via Perl to read in files and perform queries etc
such as
system("consult(roy_uk).");

I get errors such as:
sh: -c: line 1: syntax error near unexpected token `roy_uk'
sh: -c: line 1: `consult(roy_uk)'

Ive only been teaching myself Perl for the last few weeks so I'm not
sure if I am even going about this is the correct way, but any help
would be much appreciated!!

thanks.
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      01-30-2007
On Jan 30, 7:12 am, Kim Gardiner CS2003 <kgardine
+use...@cis.strath.ac.uk> wrote:
> I have been using perl to launch Prolog via the system("swipl");
> command. This has worked fine so far. However, when I try to issue
> commands to Prolog via Perl to read in files and perform queries etc
> such as
> system("consult(roy_uk).");
>
> I get errors such as:
> sh: -c: line 1: syntax error near unexpected token `roy_uk'
> sh: -c: line 1: `consult(roy_uk)'
>
> Ive only been teaching myself Perl for the last few weeks so I'm not
> sure if I am even going about this is the correct way, but any help
> would be much appreciated!!


You're confused about what system() does. It takes the string passed
as the argument, launches a brand-spanking new process, and executes
that command in that process. Two consecutive system() calls are
wholly unrelated. Your second call there is attempting to run the
command "consult(roy_uk)." as an actual command, just as if you'd
entered it at the command line. It is not sending that string to the
previously executed program that was run (and has already terminated)
by the first system() call.

If you want to open a pipe to a process so that you can feed it
commands, you probably want to use open() with a pipe:

open my $prog_h, '|-', "swipl" or die "Cannot start swipl: $!";
print $prog_h "consult(roy_uk).";

Of course, if you're going to want to both write to and read from this
process, this isn't going to work. You need bi-directional
communication, which is more advanced than the above. For the
details, have a read of:
perldoc IPC::Open2
If, after reading that, and making an attempt, your program does not
work as expected, please post a short-but-complete script that
demonstrates your error.

Please also read the Posting Guidelines that are posted here twice a
week.

Paul Lalli

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How can I change the default Language Firefox uses for File and Menu Commands? Just aFax MAm Firefox 1 11-06-2005 05:45 PM
commands to configure WLAN adapter parameters =?Utf-8?B?SmFnYW4=?= Wireless Networking 0 10-05-2005 11:37 AM
How to Stop Modelsim from echoing tcl commands in batch mode? Dave VHDL 0 09-08-2005 08:47 AM
Need Help Differentiating Bad Commands From Incomplete Commands Tim Stanka Python 1 08-02-2004 02:08 AM
Re: man pages for C commands (GCC commands) Ben Pfaff C Programming 4 06-28-2003 06:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57