Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Using "system" command - is it "bad practice" for perl?

Reply
Thread Tools

Using "system" command - is it "bad practice" for perl?

 
 
John Davis
Guest
Posts: n/a
 
      09-27-2004
A couple of quick questions, it is considered "bad" perl programming
(from a style perspective) to ever use the system() command to call
UNIX level commands in a script, or should the "backtick"/exec method
be used at all times (if possible).

I was working on a piece of code today and realized that after the
running the system commands as follows:

system "co -l /src/test-script2.pl"; # to checkout for RCS
system "vi /src/test-script2.pl"; # edit and process it and return
back

*** IT NEVER COMES BACK from the vi command!

system "ci -u /src/test-script2.pl";

foreach @x {
blah blah blah...
}

It did not return "control" back to my script and I had to Control-C
out of this script, and got frustrated at the system command. Is this
supposed to happen? Because in a ksh script, after doing a "vi", I
should get back to where I need to be.

Thanks!
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-27-2004
John Davis wrote:
> A couple of quick questions, it is considered "bad" perl
> programming (from a style perspective) to ever use the system()
> command to call UNIX level commands in a script, or should the
> "backtick"/exec method be used at all times (if possible).


Short answer: No.

When reading your message, I can't help getting the feeling that you
haven't studied the docs for system()

perldoc -f system

respective backticks (or the qx// operator)

perldoc perlop

Please do so, and come back if that does not answer you questions.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      09-28-2004
John Davis wrote:
> A couple of quick questions, it is considered "bad" perl programming
> (from a style perspective) to ever use the system() command to call
> UNIX level commands in a script, or should the "backtick"/exec method
> be used at all times (if possible).


Is it bad considered bad style to ever use a hammer or should I always use a
wrench.

Well, dude, those are different tools. It depends on what you want to do.

> I was working on a piece of code today and realized that after the
> running the system commands as follows:
>
> system "co -l /src/test-script2.pl"; # to checkout for RCS
> system "vi /src/test-script2.pl"; # edit and process it and return
> back
>
> *** IT NEVER COMES BACK from the vi command!


Did you vi process terminate?

jue


 
Reply With Quote
 
Shawn Corey
Guest
Posts: n/a
 
      09-28-2004
John Davis wrote:
> A couple of quick questions, it is considered "bad" perl programming
> (from a style perspective) to ever use the system() command to call
> UNIX level commands in a script, or should the "backtick"/exec method
> be used at all times (if possible).
>
> I was working on a piece of code today and realized that after the
> running the system commands as follows:
>
> system "co -l /src/test-script2.pl"; # to checkout for RCS
> system "vi /src/test-script2.pl"; # edit and process it and return
> back


In UNIX, it's better to use:

my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';
system "$editor /src/test-script2.pl";

VISUAL is the visual (screen) editor but many people set EDITOR as it.
EDITOR is the line editor. The emacs users will thank you.

--- Shawn
PS I use vim (VI Improved)
 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      09-28-2004

"John Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
>A couple of quick questions, it is considered "bad" perl programming
> (from a style perspective) to ever use the system() command to call
> UNIX level commands in a script, or should the "backtick"/exec method
> be used at all times (if possible).


They both do different things, so it depends on the circumstances.

On a general note, if you find your Perl script is full of system commands,
then you either aren't using the native Perl equivalents, or the script
would have been better written as a shell script.


 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      09-28-2004
John Davis wrote:

> A couple of quick questions, it is considered "bad" perl programming
> (from a style perspective) to ever use the system() command to call
> UNIX level commands in a script, or should the "backtick"/exec method
> be used at all times (if possible).


Use system() for anything that is interactive, like "vi", where the output
is expect to go directly to the screen (STDOUT).
Use backticks when you want to process the program's output yourself.

It's not a question of "bad" programming practice if you use the wrong
one; it's just that your program won't work with the wrong one.
-Joe
 
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
suppress opening command window after using os.system command boriq Python 4 06-12-2008 10:42 AM
NCQ (Native Command Queuing) and TCQ (Tagged Command Queuing) Explained Silverstrand Front Page News 0 04-17-2006 05:49 PM
Need simple command for validating xml files at the command line Bernd Oninger XML 1 07-07-2004 06:20 PM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net 4 10-23-2003 11:09 AM
copying value of DDL in a Datagrid "pre-edit command" to value in "post edit command" San Diego Guy ASP .Net 0 08-07-2003 08:59 PM



Advertisments