cancel
Showing results for 
Search instead for 
Did you mean: 

Data Services cmd failing with exit code 1 and error 50306

Former Member
0 Kudos

Guys,

I am trying to run below command through Data Service using Script, this script will try to delete files older than 6 days, this works perfectly fine when i run from cmd prompt and i am getting exit code 1 error from DS, need expert help here.

print(exec('cmd.exe','forfiles /p "D:\\Test" /s /d -6 /c "cmd /c del @file"',1));

Error:

Job <DEL_SCRIPT> is terminated due to error <50306>.

Function <exec> failed to execute program <cmd.exe forfiles /p "D:\Test" /s /d -6 /c "cmd /c del @file">. Program terminated

with exit code <1>.

Thanks

Nitin

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Make sure that you dont have (older than 6 days) sub-directories in the D:\Test folder. if sub-directories are there use below command:

print(exec('cmd.exe','forfiles /p "D:\\Test" /s /d -6 /c "cmd /c if @isdir==FALSE del /q @file"',1));

former_member187605
Active Contributor
0 Kudos

Are you sure the DS userid has the authorisations te delete from that folder?

Are you sure there's at least one file older than 6 days?

In any case, the command will run into an error.

Former Member
0 Kudos

Hi Dirk,

Yes DS has the relevant access to the Folder and i do have files older than 1 day. It works fine from cmd prompt but from DS.

Thanks

Nitin

former_member187605
Active Contributor
0 Kudos

6 days, not 1 day!

akhileshkiran
Contributor
0 Kudos

Hi

Try the below one it show work if you use the flag 8.


exec('cmd.exe','forfiles /p "C:\\Test" /s /d -6 /c "cmd /c del @file"',8);

More About Flags:

Reference:

Regards,

Akhilesh Kiran.

Former Member
0 Kudos

Hi Akhilesh,

Thanks for the reply.. If i use "8" as exit code, the DS job will go to success, but the cmd will never get executed .

Thanks

Nitin

akhileshkiran
Contributor
0 Kudos

Hi

I tried it and it was working fine.

let me show you with the example.

The above highlighted files are older than 6 days and these should be deleted according to you scenario.

output:

Regards,

Akhilesh Kiran.

former_member187605
Active Contributor
0 Kudos

Of course, it works fine. There's nothing wrong with the command. If it works in Windows, it will also work in DS.

The main issue here, and it's always the same story, is that when run from DS, it's run from a different user with different authorisations than when you do it manually from the command prompt.

Former Member
0 Kudos

Hi Akhilesh,

Thanks for checking out this for me , finally i was able to get it resolved, by using below code, i realized forfiles was not getting recognized  somehow, after providing the full path it worked.. Not sure of the reason though, may its not set properly in system variable ..

exec('cmd.exe','C:\\Windows\System32\forfiles.exe /p "F:\\Files\Nitin" /s /d -6 /c "cmd /c del @file"',8)

Thanks Again..

former_member187605
Active Contributor
0 Kudos

And from within a different environment, of course, with different settings for system variables.