3

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.

The problem:

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.

My question:

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.

Thanks!

2
  • 1
    I'm not a networking expert, but mapping a network drive does not expose all of the remote system's functionality to your local system. Connection via a different protocol (such as SSH) is required to run shell commands. Apr 26, 2013 at 3:38
  • This isn't specifically a programming question (and @DanielStandage is correct). You want the superuser or serverfault websites. I suggest learning a little about system administration and networking before proceeding with this task.
    – undefined behaviour
    Apr 26, 2013 at 4:19

1 Answer 1

3

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.

3
  • I was under the impression that the Windows CLI did not include SSH. My current machines are running OS X and Linux, so I can't check myself... Apr 26, 2013 at 3:58
  • Great, thanks for the info Barton, ssh definitely seems to be the way to go. I'll investigate this issue and CopSSH further. Apr 26, 2013 at 18:25
  • @DanielStandage There's no SSH client on Windows by default. But it's possible to install it. Apr 27, 2013 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .