Every last itteration failing in start loop stage - datastage

I have created a genric sequence job.
Exec command >> start loop >> job activity >> end loop
Here in exec command stage i have written a script to get list of files present in directory as csv values, and the file count will varry.
file,file2,file3
But when i run the job every last itteration fails showing below error
#job_activity,error calling DSSetParam(name), code =-4

Not sure if you figured it out yet, but I was having the same problem. Per one of your comments about handling the #FM, are you doing that inside an Ereplace function (e.g., Ereplace(<string>,#FM,'')?
I had this in my StartLoop activity and after trying several different things, I fixed the issue by adding a new UserVariables activity in-between the command and loop and moving the Ereplace function to it and then using the new user variable as the list in the loop.
Assuming this works for you too, your new flow will look something like this: exec command (where you pull the list and nothing more) >> user variables (create one variable with the Ereplace(<name>.$CommandOutput,#FM,'') [replace the name with whatever you called your exec command] in the expression) >> start loop >> job activity >> end loop.
I haven't been able to find anything from IBM as to why adding that extra step works (hopefully someone else is more successful), but it's what did the trick for me.
Hope that helps.

Related

How to best print output to command window during a loop in Matlab?

I have a loop which iterates through a list of ID numbers paired with a given stress value. The code works fine, except there is no guarantee that the lists have identical lengths. I currently have an if isempty(stress_value) loop with a continue statement if an ID number doesn't have corresponding stress value. All of this takes place in a for id = 1:num_ids loop.
I am now trying to print this id value (class 'double') to the command line, if it doesn't have an assigned stress value, so if the isempty statement is True, prior to continuing out of the loop. As an example, if I set num_ids equal to 101, but the list I'm iterating through only has ID values 1-100, I want to output this 101 ID to the command line.
I've tried printing as an error like this:
error(['The following ID does not have an assigned stress value: ',id])
Here id simply prints as e however when I try this in the command window, which I don't quite understand. When I run it in the script nothing is printed to the command window.
I have also tried simply adding a display command for the id to the loop as follows, however when I run the code nothing shows up again:
disp(id)
Sorry for the simple question, but I have not found an effective way to do this yet, and would appreciate your feedback!
Check the fprintf. You can format your output just like you want.
for id=1:num_ids
% do something
if isempty(stress_value)
fprintf('The following ID does not have an assigned stress value: %d\n',id)
continue
end
% do something
end
The error function will stop code execution.
The display function only prints the value of the variable, without printing the variable name.

Processing a list with Powershell on a Scheduled Task

I'm a newbie to powershell, so I'm not sure if I am over thinking what I want to do, hopefully somebody can help me out.
I want to create a Windows scheduled task that calls my powershell script every 4 hours, no problems there. The script needs to process a list of ID's that range from 1 to 140,(They skip a few here and there which makes this harder) the script is just calling another external program that takes about 2 hours per ID, we give it 4 hours to be safe. So upon the powershell script loading, it needs to read from a file the last scan it did, I can do that using
$lastscan = Get-Content'lastScan.txt'
Then the script needs to find the next object in the list, which may skip a number here or there so it's not as simple as just incrementing the last scan run. Once it has the next ID it will kick off the scan and save the new value to the text file named "lastScan.txt" and exit. The only thing I need help with, is how to find the next scan in my list based on the lastscan run. The list is seperated by newline, but I could edit it if it makes it easier.
1
5
6
9
etc, etc, ...
Assuming you have a string array that was populated with Get-Content and assuming the array did not contain duplicates, you could use the Array.IndexOf method to get the index of the current id and then return the next element in the array. Example:
$x = "1","2","3"
$currentId = "2"
$nextIndex = [array]::IndexOf($x, "2") + 1
$nextId = $x[$nextIndex] #nextId should now be "3"

same input for interactive command in Perl script

In Perl script I am using command of unit(external command) using system
but that command need some run time input from user. Every time I want to give similar input which is stored in variable.
My command is:
system("dt ci $dest_file");
after this command my script is waiting for user input,
lets say I want to give "re base" as input to this every time
How can I give fix input every time it asks?
Please help, I am working on windows 7.
I want to make script completely automated... it should not wait for user input
If you call your script like this:
perl test.pl < input.txt
It should take the content of the file as an input. ( this is working with STDIN read )

How to retain a value in variable for consecutive execution of the pl script

I am new to perl scripting. Need your suggestion for the same
I have a xyz.pl script which runs to success or failure. If it fails, I need to save the checkpoint where it failed e.g. the failure name in a variable
$var=job[0];
When I rerun xyz.pl for the second time, it should read this variable $var and picks its value and start from job where it failed and not from the beginning.
In perl, is it possible? Is there variable which can retain the value for the above scenario for consecutive runs of the script.
Please advise.
A variable cannot survive the end of a script. However, you can save the value into a file from which you can later read it back into another run of the script.

Running a matlab program with arguments

I have a matlab file that takes in a file. I would like to run that program in the matlab shell, such as prog. I need to implement it so that it takes a number of arguments, such as "prog filename.txt 1 2 which would mean that i can use filename.txt and 1 2 as variables in my program.
Thank you!
In order to make a script accept arguments from the command line, you must first turn it into a function that will get the arguments you want, i.e if your script is named prog.m, put as the first line
function []=prog(arg1, arg2)
and add an end at the end (assuming that the file has only one function). It's very important that you call the function the same name as the file.
The next thing is that you need to make sure that the script file is located at the same place from where you call the script, or it's located at the Matlab working path, otherwise it'll not be able to recognize your script.
Finally, to execute the script you use
matlab -r "prog arg1 arg2"
which is equivalent to calling
prog(arg1,arg2)
from inside Matlab.
*- tested in Windows and Linux environments
Once your function is written in a separate file, as discussed by the other answer you can call it with a slightly more complicated setup to make it easier to catch errors etc.
There is useful advice in this thread about ensuring that Matlab doesn't launch the graphical interface and quits after finishing the script, and reports the error nicely if there is one.
For example:
matlab -nodisplay -nosplash -r "try, prog(1, 'file.txt'), catch me, fprintf('%s / %s\n',me.identifier,me.message), exit(1), end, exit(0)"
The script given to Matlab would read as follows if line spaces were added:
% Try running the script
try
prog(1, 'file.txt')
catch me
% On error, print error message and exit with failure
fprintf('%s / %s\n',me.identifier,me.message)
exit(1)
end
% Else, exit with success
exit(0)