FC does not work from SQL Job

  • Hello

    I have a problem run fc command from sql job. here is my string in cmd file that I am trying to run from SQL Job:

    fc c:\temp\counts1.out c:\temp\counts2.out > c:\chicmpre\result.out

    If I run it from DOS, works just fine. From SQL Job-fails and does not giving me any error.

    Any ideas?

    Dos version just in case: Microsoft Windows 2000 [Version 5.00.2195]

     

    Thank you in advance

  • Did you define the job step as an Operating System Command (CmdExec)?  If so, change it to a T-SQL Command and just use

    xp_cmdshell "fc c:\temp\counts1.out c:\temp\counts2.out > c:\chicmpre\result.out"

    I don't know exactly why, but I have had many problems over the years with CmdExec, but xp_cmdshell seems to work every time.

    /*****************

    If most people are not willing to see the difficulty, this is mainly because, consciously or unconsciously, they assume that it will be they who will settle these questions for the others, and because they are convinced of their own capacity to do this. -Friedrich August von Hayek

    *****************/

  • thank you

  • Hello Konstantine,

    I never played a lot with SQL Job, but I did a test with fc and it worked.

    In the general tab of the Edit Job step Window (where you also choose operating system as the type of the job), type :

    fc c:\temp\counts1.out C:\temp\counts2.out

    as the Command.

    In the Advanced tab of the same window specify the output file :

    c:\chicmpre\result.out

    Also for this job to work properly I had to set the "Process exit code of a successfull command" to 1 instead of 0.

    If I leave it to 0 I always have the job failed message even if the files were compared successfully.

    If anyone have any idea on the reason for this last stated behavior, just post it.

    Hope it helped,

    Carl

  • Please anyone correct me if I am wrong. I took a look at the process exist code for fc.exe and it is "1" for success and it is "2" if file not exists to compare and other failure, etc.  As long as you called fc.exe right way, you can change the exit code (Process exit code of sucessful command) set to "1" and it will give you the right job status.

    There is a little problem with that still, I don't know why yet but if you do that from job, it succeed and out put log from job history gives the right information but it didn't created the output file so there is two way to approch. One is from Advance tap and generate the output file from there and the other one is to make the command as batch file and run that batch file from job. Both should work..

    Good luck and hope other has better idea though..

  • thank you everyone,

    solution to use  xp_cmdshell worked, so I used it.

    and it working just fine on Win 2003 server. My problem exist on Win 2000(2 edition). Version of DOS older, so fc does not run properly if called from cmd file.

     

    Thank you again for all your help

     

Viewing 6 posts - 1 through 5 (of 5 total)

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