Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question

migrated from stackoverflow.com Apr 26 '13 at 7:27

This question came from our site for professional and enthusiast programmers.

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. –  Daniel Standage Apr 26 '13 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 '13 at 4:19

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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... –  Daniel Standage Apr 26 '13 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. –  thomas.cloud Apr 26 '13 at 18:25
    
@DanielStandage There's no SSH client on Windows by default. But it's possible to install it. –  Alexey Ivanov Apr 27 '13 at 12:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.