|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
how to invoke external program and capture its output
Hi all, I am using an external binary to view memory starting from a specific address and i want to automate this via PERL however there are problems. Hope you can help me ..thx The output of the programme is like below: Code:
bash-3.2$ mem_disp 12B21D20 100 Opening RO Data Memory File scp.ro Opening Memory File CP2.16.0000000c.18.pmd.raw 12B21D20 12B6E500 186CAF00 12D81A00 00000010 *.....l..........* 12B21D30 000000AA 01060009 00000088 00000000 *................* 12B21D40 F05500FF 00019E02 00030000 00047849 *.U............xI* 12B21D50 0001013F 0001012F 805A0022 00593FC1 *...?.../.Z.".Y?.* 12B21D60 A5020000 480E05ED 00010000 00900058 *....H..........X* 12B21D70 00000000 00000000 00000000 00000000 *................* 12B21D80 43616C6C 50726F63 00000000 00000000 *CallProc........* 12B21D90 00000000 00000000 43616C6C 50726F63 *........CallProc* 12B21DA0 5F537663 5F534259 00000000 00000000 *_Svc_SBY........* I have around 30K of addresses which i want to send each to the programme above and split & save in a seperate log file ..i firstly tried to verify that programme executes and run properly for just 1 address in the list, however i can`t see all the output ( see just 1 line) when i run the perl script below: ============================================================ Code:
#!/usr/bin/perl -w
open (FILE, 'addr.txt');
foreach my $line (<FILE>){
$command = `mem_disp $line 80`;
print "$command";
}
close (FILE);============================================================= This gives the following output: Code:
bash-3.2$ split.pl sh: line 1: 80: command not found Opening RO Data Memory File scp.ro Opening Memory File CP2.16.0000000c.18.pmd.raw 12B21D20 12B6E500 *.... * ------------------------------------------------------------------- ---------- Post updated at 11:23 AM ---------- Previous update was at 11:09 AM ---------- I think perl just cant see 80 in the command ..because the output is same as saying mem_disp <addr> without the number at the end..
Last edited by Corona688; 08-03-2012 at 12:30 PM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
I think you need to type ./myscript.pl, not myscript.pl, since PATH doesn't include the current directory for security reasons. You certainly don't need perl to do something this simple -- especially when all you do in perl is run 30,000 more shells!! This does it all in one shell: Code:
while read LINE; do mem_disp "$LINE" 80 ; done < input.txt > output.txt |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thx but this is the initial step, I need to split the output and assign them to variables, make some arithmetic operation then save them in a seperate report file . i believe using perl for this makes sense.
by the way ./split.pl did give the same result.. |
|
#4
|
|||
|
|||
|
Running 30,000 individual, separate shells to run 30,000 commands is wrong, period. That's like making 300 phonecalls to say 300 words. You never have to do that, even if you're processing the result in perl. There's also some useless use of backticks in there, though seeing it in perl is a first.
You could do the loop in shell and feed the result into perl through files or stdin, perhaps. I don't know why it's taking 80 as a command. It shouldn't be, unless there's odd unprintable characters there which convince it it's on a different line. Or maybe a ; Did you copy-paste the code literally or is it slightly different from what you posted? |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
ekckabatop (08-03-2012) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
hmm thx i got it now ..ok will do that in shell and process the output in perl..well i copied and pasted , script is exactly what you see here ..anyway thanks for advice ,,
|
| Sponsored Links | ||
|
![]() |
| Tags |
| perl |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Invoke unix script using c program | somi2yoga | UNIX for Advanced & Expert Users | 1 | 09-27-2010 07:50 AM |
| Invoke perl program from Ksh | mahalakshmi | Shell Programming and Scripting | 10 | 12-19-2006 07:46 AM |
| Invoke java program in script | mpang_ | Shell Programming and Scripting | 0 | 03-27-2006 09:05 PM |
| Invoke java program in different processc d | liux99 | UNIX for Advanced & Expert Users | 1 | 08-18-2005 12:47 AM |
| Capture output of program to file with limited filesize | spectre_240sx | Shell Programming and Scripting | 7 | 04-13-2005 05:40 PM |
|
|