I am running an exec command from a Data Services Script that runs a batch file that deletes a file.
My command looked like this to start with:
$V_Extract_Status = exec('[$$ScriptFolder]\\DeleteProcessedFiles.bat' , '[$$DataFolder_Stage]\\$G_Agency]\\[$G_Department]\\Data\\',8);
Both $$ScriptFolder and $$DataFolder_Stage contained properly formatted, fully qualified directory paths, accessible to the job server, and separated by the \\ characters, for use in exactly this kind of script.
My problem is this.
The first part of the statement, that calls the batch program works fine, the extra \s get stripped off, and it calls the batch file successfully.
In the second part of the script, however, it's not stripping the extra \, and it's causing the batch file to throw an invalid path error. I've added all kinds of error catching both in data services and in my .bat file to show me the directory it's trying to access, and at every step of the way it's showing me something like 'E:\\valid_path\\valid_agency_path\\valid_dept_path\\Data\\'
So, i thought maybe Data Services was just trying to be extra helpful, and not evaluate the \ at escape characters in the parameter part of exec, so I removed the extra \s in both [$$DataFolder_Stage] and in the exc statement, so that it now looks like this:
$V_Extract_Status = exec('[$$ScriptFolder]\\DeleteProcessedFiles.bat' , '[$$DataFolder_Stage]\$G_Agency]\[$G_Department]\Data\\',8);
I had to leave the one extra \ at the end because otherwise it escaped the closing quotation mark.
Ran the job again and got the SAME results, it evaluated out the path to 'E:\\valid_path\\valid_agency_path\\valid_dept_path\\Data\\'.
It added the quotes back in for me!
I even tried breaking both halves of the exec call out into two separate variables and made my call like this:
$V_Extract_Status = exec'($Script_path,$File_path,8);
I had it print out both $Script_path and $File_path before I executed and looked at the trace. It confirmed the behavior.
$Script_path evaluated correctly to E:\valid_path\DeleteProcessedFiles.bat and $File_path evaluated to E:\\valid_path\\valid_agency_path\\valid_dept_path\\Data\\.
If I put in one \ it added a second one for me, if I put in two \\ it ignored the escape and still output two.
Has anyone seen anything like this before?
(Just to cover the obvious bases, I know there isn't a permissions file, the script executes fine when executed from the command line on the job server with the service account that run's jobs and the appropriate number of \ in it. The problem only happens when I execute it via data services and this extra \ gets put in)
I can't copy and paste my exact code and error messages in, but I can try and provide any information other than a direct copy and paste that would be helpful to troubleshoot the problem.
My next attempt is going to be trying to manually build the directory path by piping together all the directories to see if I can get it to somehow behave consistently that way, but i'm missing something more obvious, I'm open to suggestions.
Thanks!