.bat file fails in SSIS

  • I have created a Execute Process task that runs a .bat file. This bat file creates a very small .txt file.  When I execute the .bat file directly from windows explorer it runs successfully and creates the text file, but when I execute the process task in ssis it fails but it's not giving me a specific error desc other than "the process exit code was "1" while the expected was "0", AND, it doesn't create the text file.
    [Execute Process Task] Error: In Executing "\\MAINDRIVE\subfolder$\dept_folder\Inbound\Create_DONE_File.bat" "" at "\\MAINDRIVE\subfolder$\dept_folder\Inbound", The process exit code was "1" while the expected was "0".
    The code inside the .bat file is
    ECHO OFF
    fsutil file createnew "\\MAINDRIVE\subfolder$\dept_folder\Inbound" >"DONE_FILE.txt" 53248

    Has anyone come across this error before? if so, what could be the issue?

  • From my experience there could be a whole handful of possible causes.  Permissions, how wscript.exe or cscript.exe is invoked, etc.

    I would try variations of whether you have cscript.exe + the bat path, or wscript.exe + the bat path, etc.  Basically play with the syntax of the actual task or command path ...

    I've usually had to include cscript.exe  for vbs's, anyway ... this may get you thinking...

  • BI_Developer - Tuesday, September 19, 2017 12:13 PM

    I have created a Execute Process task that runs a .bat file. This bat file creates a very small .txt file.  When I execute the .bat file directly from windows explorer it runs successfully and creates the text file, but when I execute the process task in ssis it fails but it's not giving me a specific error desc other than "the process exit code was "1" while the expected was "0", AND, it doesn't create the text file.
    [Execute Process Task] Error: In Executing "\\MAINDRIVE\subfolder$\dept_folder\Inbound\Create_DONE_File.bat" "" at "\\MAINDRIVE\subfolder$\dept_folder\Inbound", The process exit code was "1" while the expected was "0".
    The code inside the .bat file is
    ECHO OFF
    fsutil file createnew "\\MAINDRIVE\subfolder$\dept_folder\Inbound" >"DONE_FILE.txt" 53248

    Has anyone come across this error before? if so, what could be the issue?

    Usually, you need to be sure of at least two things.
    1.) The SSIS package runs under the security context of whatever made it execute, so if you run it via a SQL Agent Job, then the account that the Agent runs under will need appropriate permissions to the folder location(s?) that the script touches, including any parent folders that script might navigate or list files (or directories) from.  Alternatively, if you run the SSIS package via the Windows Scheduler, then whatever user is logged on and running that scheduled task would need those same permissions.
    2.) The script being run does not assume what drive letter and/or folder is the "current folder".   This one is a pretty common mis-step, as you don't have control over that, so your batch file should be forcing it.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Now that I've looked more closely at your batch file, there's a number where I'd guess it doesn't belong.
    What is the significance of the 53248 ?   It appears AFTER a command line output redirection destination,
    and probably isn't having any effect on the fsutil program, so if it needs to, that may also be a problem.
    Either that or the redirection doesn't work right and the Execute Process Task fails due to a syntax error.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • It looks like it's not seeing the filename and size. Did you try:
    fsutil file createnew "\\MAINDRIVE\subfolder$\dept_folder\Inbound\DONE_FILE.txt" 53248

    Sue

  • Thanks all,

    Steve,
    The 53248 is the size of the text file I want. Basically it's telling the process to create a minimal text file of 56 KB in size.

    Sue,
    I went ahead and enclosed the file name inside the quote marks, and changed to echo on and pause to see what's happening and it looks like to be able to execute the fsutil utility I need to have admin rights (screen shot below).  Is there a way to do simple cmd.exe create file command?

    \\MAINDRIVE\subfolder$\dept_folder\Inbound\>ECHO ON

    \\MAINDRIVE\subfolder$\dept_folder\Inbound\>fsutil file createnew "\\MAINDRIVE\subfolder$\dept_folder\Inbound\DONE_FILE.txt" 53248
    The FSUTIL utility requires that you have administrative privileges.

    \\MAINDRIVE\subfolder$\dept_folder\Inbound\>PAUSE
    Press any key to continue . . .

  • One thing I'll try to debug things like this is use a simple command and direct the output to a file. For example:

    dir \\MAINDRIVE\subfolder$\dept_folder\Inbound > output.txt

    Just to check permissions and  can I see the file/folder.

  • The 53248 is the size of the text file I want. Basically it's telling the process to create a minimal text file of 56 KB in size.


    Just a quick aside: I think you meant 52kB.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • BI_Developer - Wednesday, September 20, 2017 8:40 AM

    Sue,
    I went ahead and enclosed the file name inside the quote marks, and changed to echo on and pause to see what's happening and it looks like to be able to execute the fsutil utility I need to have admin rights (screen shot below).  Is there a way to do simple cmd.exe create file command?

    If you are sure you have permissions to that directory - check what Steve Jones showed you - then try doing something like:
    @echo off
    break>"\\MAINDRIVE\subfolder$\dept_folder\Inbound\DONE_FILE.txt"

    Sue

  • Looks like there is a C# way of doing this, if you're happy doing some scripting. A quick Google turned this up:

      private void CreateDummyFile(string fileName, long length)
       {
        using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
        {
          fileStream.SetLength(length);
        }
       }

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Does the executing user in SSIS have Access to the Folder and permission to execute the Batch file?

  • Thank you all for your input. I was out of the office, but now that I'm back, I'll explore each of the posts and report back with findings.

  • I had got same error so i check by putting echo on and see what is issue after each line.
    For me it is issue for % in the password of SFTP site. I was using Winsscp and putting my file over in SFTP Site.

  • sks_989 - Tuesday, September 26, 2017 2:28 PM

    I had got same error so i check by putting echo on and see what is issue after each line.
    For me it is issue for % in the password of SFTP site. I was using Winsscp and putting my file over in SFTP Site.

    So, have you resolved the problem then?

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Yes Steve we resolved issue by removing ! character from password.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic. Login to reply