I am making a desktop application in C# using Windows forms. The application connects to a Unix server (each user has a separate login credential and separate environment variables and .bash_profile) and runs scripts and sends back the output to the Windows form.
I am running a Perl script in Unix through ssh .net. Say abc.pl. This works fine, but inside the script I call another executable (cpp executable).
In my C# code I have given the entire path for the script and so it runs. Inside the script the entire path to the executable is given and so it also runs. But the executable fails because it doesn't get its corresponding required .so file.
The .so file is present in the library and the path to the library is set at .bash_profile.
I know that when I use ssh .net I am actually using a non interactive ssh session and so I would not have access to the environment variables or the .profile but I have tried many things as to putting ~/.bash_profile in my Perl script in the hope that the profile would be called and set in the ssh session and many other things but to no avail.
Can anybody tell me a workaround or how to run a cpp exec inside a Perl script using ssh .net from Windows platform
EDIT :- Importing the environment variable or rather setting the environment variable was the only way out but how to go about it was the real challenge. I chose to set the environment variable path for the Library for the duration of the script. In that way the SSH session, when it runs the script will have the path to the library set in the perl script for the sesssion and hence the executable will run smoothly. The code I used is :- $ENV{'LD_LIBRARY_PATH'}="$ENV{LD_LIBRARY_PATH}:/path/to/library";
EDIT2:- If by any chance you want to use all the environment variables present in your .profile of your interactive shell then you can run the entire .profile for your non interactive ssh session as well and then you wouldn't have to worry about setting the environment variables in your perl script. For example you CAN frame your command somewhat like this :- command = ". .bash_profile; actual command"; var cmd = ssh.RunCommand( command ); var result = cmd.Execute(); The .profile will run in your new non interactive shell and set the environment variables for the entire duration of the ssh connection.
PATHenvironment variable in your Perl code. You can either hard code the path to the library or parse a.bash_profileto check what the value should be. Or there may be another way that your Perl program can discover the correct setting forPATH- Borodin