Re: How to execute a command line in Perlscript

From: Eric SALGON (eric.salgon_at_mane.com)
Date: 02/06/04


Date: Fri, 6 Feb 2004 11:17:41 +0000 (UTC)

Unfortunatly, I have implemented "shell" and "puts" functions in my ASP code
but `$_` return no result in @output array with a simple 'dir' command.

I'm afraid it's a problem of right on my IIS server.

Eric

In article <elvUb.19067$Fp6.2360@newssvr16.news.prodigy.com>,
ceo@nospan.on.net says...
>
>Eric SALGON wrote:
>> Hi,
>>
>> Is there someone who knows how to execute a command line (such a simple
echo
>> cmd) in PerlScript.
>>
>> I hve tryed '' or system() but the result is the same: no result but no
error
>> !
>>
>> This syntax works fine in a perl program but not in PerlScript
>>
>> An idea ?
>>
>
>I just realized I didn't answer your question in my last response.
>
>First of all, as a general rule, and one that is outlined in the FAQ
>(and asked about a lot here is) system() does NOT provide output. But
>most especially in the Windows world where Microsoft writes their own
>rules, this is also not the case in either ASP or WSH (still assuming
>you are talking about "PerlScript" and not "Perl script.")
>
>Using output wrappers in the ASP and WSH worlds for outputing a string,
>the following code will work in both worlds for outputing a "system"
>command:
>
>sub shell {
>
> my @output;
> for (@_) { push( @output, `$_` ) }
> chomp( @output );
> return wantarray ? @output : \@output;
>
>}
>
>puts( shell( 'dir /l/on/' ) );
>
>or you can:
>
>puts( shell(
> 'dir',
> 'type c:\\autoexec.bat',
> 'dir c:\\winnt\\system32',
> 'command4',
> 'command5',
>));
>
>If:
>
>ASP: sub puts { for (@_) { $Response->Write( "$_\n" ) } }
>WSH: sub puts { for (@_) { $WScript->Echo( "$_\n" ) } }
>
>Incidentially using PerlScript in Windows allows you this convenience.
>The "official" Microsoft "interface" (read "complicated and
>convolluted") for executing a command in a scripting environment (both
>ASP and WSH) is WshShell.Exec() (which takes two calls to set up.) You
>can do this in PerlScript if you want, but the regular Perl way of
>executing a system command works much smoother.
>
>HTH,
>Chris
>-----
>Chris Olive
>chris -at- --spammers-are-vermen-- technologEase -dot- com
>http://www.technologEase.com
>(pronounced "technologies")
>
>



Relevant Pages

  • Re: How to execute a command line in Perlscript
    ... My question was for "PerlScript" under ASP, and the 'Echo' command was only a ... my goal is to run the 'dnscmd' command (which is used to manage dns ... >> cmd) in PerlScript. ... PerlScript under ASP and PerlScript under Windows ...
    (comp.lang.perl.misc)
  • Create a Shell Object in ASP
    ... I want to run batchfiles via the Shell, ... I'd like the server to start a command line ntbackup ... if a users selects to do so on an ASP in his webbrowser. ...
    (microsoft.public.scripting.wsh)
  • Create a Shell Object in ASP
    ... I want to run batchfiles via the Shell, ... I'd like the server to start a command line ntbackup ... if a users selects to do so on an ASP in his webbrowser. ...
    (microsoft.public.inetserver.asp.general)
  • Bash-4.0 available for FTP
    ... Unlike previous bash distributions, this tar file includes the formatted ... The shell has been changed to be more ... rigorous about parsing commands inside command substitutions, ... Changes have been made to the Readline library being released at ...
    (gnu.announce)
  • Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... BASH BUILTIN COMMANDS ... last command exited within ... unless the shell is not exeâ ...
    (comp.os.linux.misc)