A little background:
I am trying to interact with data I have saved in Perl files using a program I wrote in C using the Win32 API. The C program is in Windows and the Perl files are accessed through a mapped network drive in a Unix environment. I am using perlembed and am successfully pulling the data I want from the Perl files using the embedded Perl interpreter & Perl subroutines called from C.
I have to run Perl scripts that are already in place on the Unix side. The function of these scripts is to check the syntax of the Perl files and check them into a revision control system that I am using. The scripts call some Unix specific commands like
pwd that cause the C program to break when I use
system(perl perl_file). There is quite a bit of legacy Perl code so I don’t think I can modify any of the Perl check scripts that need to be called.
How am I able to execute a Perl script in a Unix environment from the C program on the Windows side? I came across this question suggesting the use of cygwin but that seems to be just another environment in between Unix and Windows. I thought that there might be some way into allowing the C program to use a C shell in the mapped network drive to run the Perl script but I didn’t find any examples of this anywhere. Or maybe I could have the Perl interpreter in the Unix environment run the program (using the shebang line)? I hope this isn’t a dumb question. I just did so much work to be able to manipulate the Unix Perl data from the Windows side & it is frustrating to not be able to complete my task because I can’t run a Perl script.
If the Unix box is running an ssh server, you can set up a public private key pair on the Windows box, and add the public key to
$HOME/.ssh/authorized_keys on the Unix box. This should allow your Windows program to run ssh commands without entering a password.
At that point, you can do something like this in the C program:
system("ssh user@host 'perl /path/to/script.pl'");
I’m leaving out quite a number of details… you will want to pay attention to the security of the Windows account that is calling the perl file; in order to run the script without entering any password whatsoever, you’ll need to keep the password for the ssh key blank, but that means that you want to lock down the private key so that no one else has read access to it, otherwise Eve will be running arbitrary perl code on your Unix box, and that’s never a good thing.
For a Windows SSH Client, I recommend CopSSH; it’s one of several Windows ports of OpenSSH; it handles the management of ssh key pairs more sanely than the other ports that I’ve used.