Search code examples
windowsperldirectorypathrelative-path

How to call a script in a subdirectory from Perl using system (Windows)


I have a base directory, call it MAIN and two subfolders, SCRIPTS and WORK. When using the following line of code, the script calls upon the job and runs it, only if job_name is in the MAIN folder, then prints output or error to job_name.out/.err in the WORK folder.

system("$job_name > ./WORK/$job_name.out 2> ./WORK/$job_name.err");

If I move the jobs into SCRIPTS then I cannot seem to find an efficient/simple way to call upon it.. I figured something similar to the following code would work:

system("SCRIPTS/$job_name > ./WORK/$job_name.out 2> ./WORK/$job_name.err");

But I get errors like:

  • SCRIPTS is not recognized as an internal or external command......
  • The system cannot find the path specified.

How can I compose this command to get it to work from a subdirectory?


Solution

  • On Windows, filepaths are specified with backslashes (\).

    Instead of system("SCRIPTS/$job_name"...), try system("SCRIPTS\\$job_name"...)