Re: system() behaviour within object(class) instance
by castaway (Parson) on Apr 24, 2005 at 09:20 UTC
|
Sorry, but without actually seeing your code, it's hard to give a useful answer to your question. How is the object/class created, what does the system call look like?
C. | [reply] |
|
|
CGI script is like
... object instantiation ...
$obj->run()
Perl Module is like
... object definition (a very long and complex one) ...
sub run {
... normal sub definition (a lengthy one also) ...
system "command param &" and warn '';
}
so if the call is like:
system "command param" it does not work and no error is actually raised in any mode
system "command param &" does strangely work
the problem is that param is some internally computed runtime id and what I tested also is to assign that id to some global variable to CGI script through $main::global_var and when executing the same system "command param" it does work but it's not a suitable variant to use (so i did use & variant)
| [reply] |
|
|
calling system inside or outside a method call can not affect is behaviour in any way.
Have you checked that you are calling the external program with the right arguments? try replacing the command by "echo" and see what is printed.
If everything else fails, try some process monitoring tool like (depending of your OS) truss, strace, ktrace, etc. (btw, make it monitor forked child processes).
Maybe the program you are calling is waiting for some input from stdin, maybe $param is undef...
| [reply] |
|
|
Re: system() behaviour within object(class) instance
by tlm (Prior) on Apr 24, 2005 at 12:20 UTC
|
What exactly is your criterion for determining that the program "works" or not? Are you running this on a Unix-like OS?
What you report is not the expected behavior which suggests that it depends on the specifics of your code (including the specific system call). I'd need to see more real code than what you show in your reply to castaway. Could you come up with a small script that reproduces the behavior you describe? I find that in the process of producing such a scriptlet the source of the problem becomes apparent.
| [reply] |
|
|
Yes, i am running fedora core 3 (perl version is 5.8.5 - the latest that is provided as fedora-style rpm).
I think if you read my first post thoroughly you will see what are my critera for determining that the program works. I can only say that i am computing some result and write it the to the database and, as i said several times, when i issue system without & it does not work, otherwise - it works.
I will try to reproduce this behaviour with a small script but when i have time to do it. Of course, if I find it wrong that means it should be a bug? and, of course, i should try with the latest version somehow. What I was eager to know is whether s.o. has experienced smth. like this or can tell me something that i might be missing.
10x for your attention :)
| [reply] |
Re: system() behaviour within object(class) instance
by polettix (Vicar) on Apr 24, 2005 at 19:29 UTC
|
At the risk of repeating what's have already been told by many others, we need to have more in-depht knowledge about what you consider "not working". In particular, I'd be interested into this: does your program continue after the system() when you DON'T put the ampersand character or does it continue smoothly?
When you call a program with the ampersand you're asking for this process to be run in background. This also means that your system() call returns immediately, leaving the process to do its work undisturbed. Now, some web server installation limit the total time of a running instance, so when the program you call WITHOUT the ampersand goes beyond these limits it will cause the calling process to be terminated by the web server. As a consequence, the spawned program itself would be terminated, and you'd miss your data inside the database.
Now, if this actually happens, your CGI script would die at the point you call system(), but unluckly we don't know what your "not working" means...
Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')
Don't fool yourself.
| [reply] [d/l] [select] |
|
|
Sorry, but i've tried to give as much details as possible. I will try to reproduce it in a simple scenario.
Yes, the program runs smoothly.
I know what is doing exactly background mode. Result is returned in a second when run from cli.
Script does not die but continue its work as everything was successful (you can see my pseudocode above, there is "and warn" part if system was not successfully executed)
10x for your attention and help. I will really try to reproduce it with some 2 or 3 simple files that to max. extent are similar to my case.
| [reply] |
|
|
| [reply] [d/l] [select] |
Re: system() behaviour within object(class) instance
by sgifford (Prior) on Apr 24, 2005 at 16:35 UTC
|
How are you checking for errors from your call to system?
| [reply] [d/l] |