check contents of a text file

  • Guys,

    I am using the Konesans file watcher to watch for a file (status.txt) to change.

    The file contains only one line of text which will be 'Build In Progress' 'Build Failed' or 'Build Sucess'

    I want to monitor the contents of the file and only continue processing if the status is 'Build Success'

    The challenge is that I need to do it without using scripts.....:w00t:

    So far I am trying this - which seems a bit long winded...

    DataFlow Task to convert the flat file to a raw file

    DataFlow Task to read the raw file into ADO recordset

    ForEachLoop container to read the ADO recordset and assign the value to a string variable

    ForLoop container inside the ForEachLoop that does not process if the value != "Build Success"

  • Read the file in a dataflow.

    Add a conditional split which redirects processing according to what has been read - two outputs: Build Success and the rest.

    Each different path sets a variable appropriately.

    Destination is irrelevant - use the trash destination.

    Now you have a variable which you can use to decide what to do next.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Thanks Phil, That was a useful lesson.

    Unfortunately I can't see how to assign the value to a variable without using a script. I have tried sending the output to a new flat file but the file gets written even if there is nothing to put into it.

  • aaron.reese (2/4/2013)


    Thanks Phil, That was a useful lesson.

    Unfortunately I can't see how to assign the value to a variable without using a script. I have tried sending the output to a new flat file but the file gets written even if there is nothing to put into it.

    OK, my flippant comment about setting a variable was not very helpful - sorry.

    But there is a way to do this, using the same technique I mentioned. After the conditional split, put a RowCount component in the 'Success' branch and fire the result into an int variable which has been initialised as zero.

    At the end of the data flow, you have an int variable which is either 0 or 1 and you can use that in your precedence constraints.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Nice one Phil,

    Worked a treat. I am up against it today but I will post a full solution later to help others.

    Obiron

  • Ok,

    This is what we did.

    Package scoped variable intIsGoodToGo (Int32)

    For-loop with Eval Expression of 1==1 to keep the package constantly running

    Konesans File Watcher looks for the file to arrive or change (we also have it set to check on start up) On detection of a change

    Data Flow Task:

    Flat file source which is the status file we were monitoring

    Conditional Split: The file contains one column which we called status. CS has two output streams 'Success' with a condition of Status == "Build Success" and 'Not Success' with a condition of Satus != "Build Success"

    The Success stream goes to a rowcount destination which puts the rowcount into intIsGoodToGo. In our case the result will be either 0 or 1 because the file will only ever contain one line

    Precedence Contstraint from the dataflow task on task Success and Expression of @intGoodToGo == 1

    The package then processes until the termination point then the for-loop evaluation kicks in and waits for the next appearance of the file. The last task before termination is to delete the file being watched for (in our case the source application will re-create it if it does not exist)

    Hope this is helpful to someone.

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

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