On windows XP, I have a bat file which calls a perl script, which itself shall contain a "make" command in a cygwin context. (I can't change this BAT -> PERL -> CYGWIN structure). This works a little bit but I don't find how to exit from the cygwin environment.
For example, in my perl script, this line seems to work :
print STDOUT "START PERL SCRIPT\n" ;
system ("$ENV{CYGWIN_HOME}\\bin\\bash | $ENV{CYGWIN_HOME}\\bin\\make -version");
print STDOUT "END OF PERL SCRIPT\n" ;
However, in my cmd.exe, this is my output:
- START PERL SCRIPT
- GNU Make 3.80 Copyright (C) 2002 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- bash-3.2$
My problem is that I stay in bash environment : the line "bash-3.2$" still waits for a command, and I cant' find a solution to exit automatically from it (the only way is to manually print "exit" in cmd.exe). My perl script is thus stopped instead of automatically continuing its jobs.
I've not succeeded with solutions such as "Using perl to run more than one system command in a row"
Do you know how to write the perl script and commands in order to get out of the bash environment and continue the perl script ?
Thanks a lot, Calim
Update
So finally I have moved to another solution. It seems to work (i.e. I go back to my perl script after the shell command is executed) ; I just hope there will be no unexpected effect. Do you have any opinion about it ?
print STDOUT "START PERL SCRIPT\n";
open ( CYGWIN , "|-" , "$ENV{CYGWIN_HOME}\\bin\\bash" ) ;
print CYGWIN "$ENV{CYGWIN_HOME}\\bin\\make -w -C /cygdrive/c/tmp/Generation makefile" ;
close CYGWIN ;
print STDOUT "END OF PERL SCRIPT\n";
2 Answers 2
Why are you piping the ouptut of bash to make?!?!?!
system("$ENV{CYGWIN_HOME}\\bin\\make -version");
Or maybe you need some environment variables set up by bash.
system("$ENV{CYGWIN_HOME}\\bin\\bash -c 'make -version'");
Comments
So finally I have moved to another solution. It seems to work (i.e. I go back to my perl script after the shell command is executed) ; I just hope there will be no unexpected effect. Do you have any opinion about it ?
print STDOUT "START PERL SCRIPT\n";
open ( CYGWIN , "|-" , "$ENV{CYGWIN_HOME}\\bin\\bash" ) ;
print CYGWIN "$ENV{CYGWIN_HOME}\\bin\\make -w -C /cygdrive/c/tmp/Generation makefile" ;
close CYGWIN ;
print STDOUT "END OF PERL SCRIPT\n";
bash | make, why? What are you trying to achieve?