im trying run set of commands in system command prompt using perl.
here code
#!/usr/local/bin/perl -w use strict; print_prompt(); sub print_prompt { print "what's name?"; system("g:\"); system("cd documents , settings/administrator/eworkspace/sample"); print `ant`; }
but throwing me following error
bareword found operator expected @ execute.pl line 11, near "system("cd" (might runaway multi-line "" string starting on line 10) string found operator expected @ execute.pl line 11, @ end of line (missing semicolon on previous line?) syntax error @ execute.pl line 11, near "system("cd documents " can't find string terminator '"' anywhere before eof @ execute.pl line 11.
how resolve ? whats possibly wrong in code? need indicate white spaces ?
these 2 lines:
system("g:\"); system("cd documents , settings/administrator/eworkspace/sample");
are broken in couple of ways. firstly, top 1 broken in way other people have described before me. \
escapes "
doesn't close quoted string , syntax of rest of file becomes broken.
but secondly, both of these lines broken in deeper way. don't think. both, effectively, nothing. system
command invokes new shell environment in run command. new environment inherits values parent environment (the 1 running code). these values include current directory. change current directory in new child environment. when system
command finishes (which happens immediately) new environment destroyed. program continues run in original environment original current directory.
you should @ perl's built-in chdir function.
Comments
Post a Comment