Executing MQ commands in Perl

If you want to capture the output of any command, we then will be writing the system command in `` or qx.

`` an qx works fine with all linux and windows system commands.

But when I execute the below code.. it is displaying the output on the screen directly instead of storing to variable

crtmqm is the command used to create queue manager in MQ Series.

$name = "clientinfo";
@output = `crtmqm $name`;
print "@output\n";

Could anyone please help me in storing the output of MQ command in perl variable.

I don't know for sure (but can test tomorrrow, whe back in the office) but i suppose that MQ is not using the usual UNIX stdout/stderr-mechanism for displaying output. What happens when you redirect the output on the commandline, like this?

$ crtmqm clientinfo > /tmp/somefile

Does the output end in the file or still on the screen? In the manual there is a parameter "-ld <pathname>" mentioned which specifies a log directory,but i suppose there only goes the logs for the newly created queue manager, not the output of the creation of the queue manager.

In case you want to just check if everything worked successfully you could just check the return code, according to this page they are meaningful (unlike other IBM tools, ~sigh~).

I hope this helps.

bakunin

FYI,
You are storing the output of it in a variable, specifically in an array variable named output. But then, you are asking the program to display the content of output (which is what you just saved) to the stdout via the print , that's why you see it displayed. Remove the print "@output\n"; and you will not see stdout in your screen. You will still see any stderr , if any.

`` and qx() does not capture stderr (reporting messages), by default, it does only stdout . If you want to capture stderr as well you need to tell it:
`crtmqm $name 2>$1`

You are right, this might account for the displaying, but thread-o/p said (emphasis by me):

So i suppose he already tested the variables content and came up empty. (Ah, well, you might have a point there ... ;-)) ) It should, even after being printed, hold content, no?

I hope this helps.

bakunin