Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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\perlapp.pl. 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\perlapp.pl’ 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 +rlapp.pl
    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;
    poj
      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/test.pl 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/library_sub.pm use strict; use warnings; use Exporter qw(import); our @EXPORT = ( 'test' ); sub test { return "library_sub::test - OK"; } 1;
        poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2020-11-30 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?