Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Problem using rshell to start Perl application

by merrymonk (Hermit)
on May 17, 2018 at 18:46 UTC ( #1214777=perlquestion: print w/replies, xml ) Need Help??

merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I use the DOS rshell command to start a Perl application. The argument for the command is C:\dir1\dir2\dir3\dir4\dirapp\ The Perl application uses a library module which I want to store in the directory …\dirapp\myperl-lib. I get access to the library module by a Perl line

use myperl-lib::library_sub;

When I type ‘rshell C:\dir1\dir2\dir3\dir4\dirapp\’ in an MSDOS window, the Perl application works as required.
When I call the rshell command from a 3rd party (none Perl based) application, rshell does not work and returns the error code 2 – which means “The system cannot find the file specified.”

Using diagnostic printing I have found that the Perl application fails on the use command.

If I add the Perl library into the Perl directory tree in which the perl.exe is stored (and used to run the Perl application) the rshell command works from the 3rd party application.

What do I have to do to get the application to use the Perl library stored in a directory used for the application?
  • Comment on Problem using rshell to start Perl application

Replies are listed 'Best First'.
Re: Problem using rshell to start Perl application
by huck (Parson) on May 17, 2018 at 19:51 UTC

    The problem is that the directory you are in when you call the perl from the MSDOS window is not the same directory you are in when it is called by the 3rd party ap so the library is not found. There are many ways to specify how to find a perl library. The one i use is to determine the directory that myperl-lib is in and specify it as i call perl. lets assume your libary is at C:\dir1\dir2\dir3\dir4\dirapp\myperl-lib. then

    perl -I C:\dir1\dir2\dir3\dir4\dirapp C:\dir1\dir2\dir3\dir4\dirapp\pe
    should do the trick.

      Thank you for that.
      I did try that and it works when I typed in the 'string' into an MSODS screen.
      Sadly it gave the error 2 when I rshelled the string from the 3rd part application.
      I did have to type in the path to the perl exe (ie c:/dir1/dir2/dir3/bin/perl.exe). However I do not think that was the problem as I recall I have to put perl.exe into the PATH so that 'perl' works.
Re: Problem using rshell to start Perl application
by poj (Abbot) on May 17, 2018 at 20:54 UTC

    try FindBin

    use FindBin; use lib $FindBin::Bin.'/myperl-lib'; use library_sub;
      I tried this and replaced
      /myperl-lib with the actual name of the folder
      library_sub with the actual name of the Perl module that contained the subs that I wanted to call

      This partially worked but a got a number similar errors of the form
      Not enough arguments for myperl-lib::library_sub::sub name and line number in myperl-lib that has the 'our @EXPORT = (' row

        Here is a Short, Self-Contained, Correct Example for you to try and then adapt to your situation and hopefully demonstrate the problem.

        #!perl # c:/path/to/dirapp/ use strict; use warnings; use FindBin; use lib $FindBin::Bin.'/myperl-lib'; use library_sub; print test();
        package library_sub; # c:/path/to/dirapp/myperl-lib/ use strict; use warnings; use Exporter qw(import); our @EXPORT = ( 'test' ); sub test { return "library_sub::test - OK"; } 1;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1214777]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-06-12 15:07 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (53 votes). Check out past polls.