Hello, Prakash,
I have to invoke/run a shell file sample.sh from within perl file.
When the perl while is executing, it should run to set some env variables.
I'm not so sure about exactly what happens here on windows, but this is a notoriously common problem and it does not generally give you what you wanted. Generally speaking, you probably won't want to use a shell script to do this. For the rarer case where you really do need to invoke a shell script, we did have
a recent thread about this and one poster, bidoun, proposed an interesting workaround (see posts #5 and #6). This may help. And even if it turns out that you don't really need to run the shell script, the illustration of how to accomplish the equivalent in Perl may help you.
I want to invoke cygwin shell from perl and then run some commands like cd, ls on the cygwin window. All this to be done by invoking through the running perl script.
OR
Any pointers on how to invoke ant target on windows from within perl script running on windows OS.
Perl has built-in functionality to do the job of cd and ls. Shelling out to do cd has the same problem that using a separate shell script to set environment variables has -- it does it in a separate process that does not propagate changes back to the parent process. Instead of that, use the built-in perl function
chdir. As an ls equivalent, there are a number of ways to do similar things, depending on exactly how you want your data returned. Check out the
glob function as well as the
readdir function. You can look at
this thread for some examples.
In general you can run just about anything with the
system function, but it doesn't always do what you think it might do if you don't understand what you are doing. In particular, if you expect it to change the state of the process running the perl, then you are likely to be disappointed.
In general, it's better to ask (yourself or others) questions like "How can I best accomplish X?" than questions like "How can I use Y?"
HTH,
Paul