Executing MQ commands in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing MQ commands in Perl
# 1  
Old 11-27-2016
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.

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

Could anyone please help me in storing the output of MQ command in perl variable.
# 2  
Old 11-27-2016
Quote:
Originally Posted by giridhar276
But when I execute the below code.. it is displaying the output on the screen directly instead of storing to 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?

Code:
$ 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
# 3  
Old 11-27-2016
Quote:
Originally Posted by giridhar276
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.

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

Could anyone please help me in storing the output of MQ command in perl variable.
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`
# 4  
Old 11-27-2016
Quote:
Originally Posted by Aia
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.
You are right, this might account for the displaying, but thread-o/p said (emphasis by me):

Quote:
Originally Posted by giridhar276
it is displaying the output on the screen directly instead of storing to variable
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing commands sequentially

Hello. I am new in shell script. Could anyone help me? I have un shell script. I need each command in it be sequentielly, when the first command ends the second starts. When the second ends et third starts, and so on Thanks in adavance (1 Reply)
Discussion started by: nurinolo
1 Replies

2. Shell Programming and Scripting

Trouble executing piped shell commands in perl code

I am trying to execute a piped combination of shell commands inside a perl program. However, it is not working as desired. This is my program, i am trying to print only filenames from the output of ls -l $ cat list_test #!/usr/bin/perl -w use strict; my $count=0; my @list=`ls -l|awk... (4 Replies)
Discussion started by: sam05121988
4 Replies

3. Shell Programming and Scripting

Executing two commands in parallel

Hi, I am stuck into a situation where i want to execute a command in my shell script well along with a previous command in order to achieve something but i am not figuring out a way. here is a snippet: service management restart rm -rf lock.file in the above, if you see, i am trying to... (5 Replies)
Discussion started by: sunrexstar
5 Replies

4. Shell Programming and Scripting

Executing commands

I need to execute a command to run my script several times with varying parameters perl ex.pl -b 130198 -e 130884 -c plot plot.txt 1_plot.txt perl ex.pl -b 1345 -e 1308 -c plot plot.txt 2_plot.txt perl ex.pl -b 1345567 -e 130898 -c plot plot.txt 3_plot.txt . . . 100's of excutions ... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

5. Shell Programming and Scripting

executing commands over ssh

Hi I am trying to send a command over ssh with a parameter but the shell fails to expand the command properly any ideas what am i doing wrong with this. This is ssh on AIX for i in 71 72 73 74 75 do for server in server1 server2 do somestr="Some String" echo "$server... (3 Replies)
Discussion started by: xiamin
3 Replies

6. Shell Programming and Scripting

Executing many commands at once

Hi, I want to run these two commands one after the other. awk 'BEGIN {OFS="\t"} {print $2}' sort -u rather than typing awk 'BEGIN {OFS="\t"} {print $2}' file1 > file2, then sort -u file2 > file3. Is it possible to run both commands on file1 then get output file3? Its kinda hard for... (5 Replies)
Discussion started by: kylle345
5 Replies

7. Red Hat

How commands are executing ?

Hi Folks, I have a small doubt, the binary commands under /bin and /sbin as well as other path binary files, if you peek deep into that, you can find the difference in the way of normal perl programming and some commands will be like binary files. how are the commands executing like the... (3 Replies)
Discussion started by: gsiva
3 Replies

8. UNIX for Dummies Questions & Answers

Executing commands after I log off

Hi, guys ! I have at home a simple network. I have a server that shares the internet connection to my computer and another another computer which is located in another room. When I want to download something, I'd like to download directly on the server, without letting my computer on. The server... (2 Replies)
Discussion started by: Sergiu-IT
2 Replies

9. Shell Programming and Scripting

Executing mpirun commands

Basically, I would like to run an mpirun query on my web server to query your databases via yours when using the BLAST program, however the server seems not able to execute even basic mpirun programs such as cpi (to calculate pi). Are there any settings I should take note of? I am running Perl... (0 Replies)
Discussion started by: tesswulf
0 Replies

10. UNIX for Dummies Questions & Answers

FTP - Executing Commands

I have written a script to ftp a file from Unix to an NT machine to authenticate ftp login I have added the information into the .netrc file when logged in using ftp the commands are not executed. Does anybody know how to make the command execute once username and password have been provided using... (2 Replies)
Discussion started by: hesmas
2 Replies
Login or Register to Ask a Question