Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Usage for system.readFile using pattern string #170

sdodds ·
WinXP environment, QuickBuild 1.2.2

I am modeling a machine independent environment in which the same product can be built on one of many machines. The machine configurations are not the same, in that Installshield or other utilities may be installed on either C: or D:. To pickup the machine-specific path to these utilities, I decided to create an 'asset file' on each machine and set variables in Basic Settings-Other Settings to pattern-matched paths in that asset file:

IsCmdBld9=${system.readFile("C:/QBAssets.txt","IsCmdBld",1)}
Devenv7=${system.readFile("C:/QBAssets.txt","devenv",1)}
.
.

In the example above, if "IsCmdBld" is found in QBAssets.txt, then this returns the line containing IsCmdBld from the file , but that <line> is returned from readFile in the form "... ... ... <line> ... ... ...".

In the above example, if devenv is not found in the asset file, the string returned from readFile is "... ... ...", and not empty as I would expect.

I don't know where the triple dots are coming from. Any insight is appreciated.
  • replies 11
  • views 5990
  • stars 0
robinshen ADMIN ·
This function is not expected to be used here. You may use ${system.readOutput("/path/to/command").trim()} to get the right variable values. The "readOutput" function executes specified command and captures the standard output as return value.

Please remember to append ".trim()" to trim off any unwanted blanks in the output.

Regards.
Robin
sdodds ·
Thanks; I'll try that. I expect that as I explore the flexibility of OGNL in other areas as a solution to our needs, I will probably use other functions where they are not expected.
drdt ·
> This function is not expected to be used here.

Can you give an example of proper usage of the system.readFile function? I would also find this useful in my scripts.
drdt ·
A sample of how to use the system.readOutput command to read from a file would also be helpful. I am trying to make it work, but I keep getting a variety of errors ranging from a simple 'file not found' or 'the syntax of the command is incorrect' to the scarier 'Malformed OGNL expression':

Malformed OGNL expression: system.readOutput("cmd /c type C:\BuildLabel.txt").trim() [ognl.TokenMgrError: Lexical error at line 1, column 35. Encountered: "B" (66), after : "\"cmd /c type C:\"]

I get this when I try to use the command:
tbbuildnumber=${system.readOutput("cmd /c type C:\BuildLabel.txt").trim()}
robinshen ADMIN ·
Please try to write the expression as:

tbbuildnumber=${system.readOutput("cmd /c type C:\BuildLabel.txt").trim()}

The OGNL expression needs that windows path being separated by double slashes.

Regards.
Robin
drdt ·
Okay, this is working, but not if I try to use variables. I have the following expression:

tbbuildnumber=${system.readOutput("cmd /c type " + var["tblabelfile"].value).trim()}

When I set tblabelfile to either 'c:\temp\buildlabel.txt' or 'c:\temp\buildlabel.txt', it works.

Likewise if I set it to '\re-depot\labels\dev\buildlabel.txt'. But *not* if I use '\\re-depot\labels\dev\buildlabel.txt', which from your posting should be the correct syntax. In that situation, I get the error 'The filename, directory name, or volume label syntax is incorrect.'

However, my need is to define tlabelfile as follows:

tblabelfile=${var["tblabelsite"]}\buildlabel.txt
(or, possibly: tblabelfile=${var["tblabelsite"]}\buildlabel.txt ?)

However, I cannot find a value for tblabelsite that allows it to work. I always get the error 'The system cannot find the path specified.' I have tried 'c:\temp' and 'c:\temp', as well as my intended network paths.

Please tell me what I am doing wrong.
robinshen ADMIN ·
This is a bug that embedded variables are not correctly evaluated as argument of external command. It will be fixed in next minor version. The patch has been sent to your mail box.

Thanks.
Robin
drdt ·
As an interim solution, I am hard-coding the location of tblabelfile in my QB configuration as follows:
tblabelfile=\re-depot\branches\proj_qa\BuildLabel.txt
tbreadbuildlabel=${system.readOutput("cmd /c type " + var["tblabelfile"].value).trim()}

tblabelfile contains a single line, which is a build number.

For different branches, I redefine tblabelfile as needed for the configuration. This seems to work, but for one thing - more than once in five tries, tbreadbuildlabel comes back as a null string.

I have a custom build step running at the very start of my build which prints out these two variables. Usually, it looks like this:
2007-03-29 13:30:45,780 [Thread-681] INFO - File:\re-depot\branches\proj_qa\BuildLabel.txt
2007-03-29 13:30:45,780 [Thread-681] INFO - Label:08.01.20.50

But enough times to make me question its reliability, it looks like:
2007-03-29 13:31:03,789 [Thread-692] INFO - File:\re-depot\branches\proj_qa\BuildLabel.txt
2007-03-29 13:31:03,805 [Thread-692] INFO - Label:

Occasionally, it comes back with no output at all, which I cannot fathom at all. Nothing is changing from one run to the next - I am just hitting 'start' 'start' 'start' over and over again to get these results.
drdt ·
On further examination, I am finding that, even when the variable appears properly in the output of my reporting build step, it is somtimes not defined later on when I try to use it in another step. Is it possible that the readOutput function is being executed every time I try to access this variable? In that case, it may be failing because the file is being accessed by another parallel task in my build, or for some other even more estoteric reason.
robinshen ADMIN ·
Yes, the variable will be re-evaluated for every reference. I did found that sometimes output of executed command can not be fully picked up by QuickBuild, and have made a fix to that in the latest build (1.2.7 build 82). Please give it a try to see it solves the problem.

Thanks.
Robin
drdt ·
I downloaded the patch and was unable to reproduce the problem in thirty passes. Thanks!