I currently have the following problem:
In an awk script, I am calling a predifend function from the END{} and handing over a command string. This string arrives flawless and is executed like this:
Not sure why your code doesnt work, i tried something almost similar and it returned the exit code from the perl script.. What is your OS and awk version ?
@vidyadhar85
Sorry I altered my code to avoid confusion. I removed the $? - that was just there to verify if at this point there is any RC other than 0. You saw the code before I altered it. Forget the $?
@n70arun
Thanks for the input, but the exit code of the command being called by system() will be assigned to the variable rc. And since I print this, it is displayed from inside the function, but not with the expected return code. The Perl script produces a 16 and not a 0, which I have tested, as said. Though I have a look at it again.
Update:
I simplified what I am doing in an extra script and it works. No clue why it doesn't work in my other script - though I will give another update when I found it.
Update:
It seems the cmd_str is a problem. It is a very long list of parameters and contains blanks, semicolons, double quotes. Somewhere there must be a problem, because when I issue the Perl script without parameters it returns a RC of 1 which is also displayed when I alter it in the script.
I have to check how I can encapsule that long string so that it will be handed over correctly and if the correct RC will be displayed.
Update:
I found out, that when there is a semicolon in string variable, that is handed over to system(), it will give the RC = 0, because the parameters delimeted by the semicolon are things like "msg=blabla" and this is a valid variable definiton in the shell, so it's RC = 0 :rolleyes:
test.sh worked, because it had a shortened version of the command, where the semicolons were left out... sorry.
I tried escaping it, but that doesn't help - any ideas are welcome.
I can't change the delimeter to something else, because the server on the other side expects them as delimeter.
$ awk 'END{system("echo test1; test2")}' bla
test1
sh: test2: command not found
Any ideas? As said, escaping and trying single quotes etc. didn't help so far.
Update:
Sorry guys, maybe I am not able to see the wood for the trees at the moment ...
Escaping worked for this case easily:
$ awk 'END{system("echo \"test1; test2\"")}' bla
test1; test2
I am currently trying to figure that out in a garbled sprintf() with lots of these. I think I am done more or less. Thanks all for trying to help. As often, the problems sits in front of the computer
I have to enclose every semicolon like a=aaa"\;\"b=bbb to make it work.