[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: executable scripts and arguments
From: |
Dupuis |
Subject: |
Re: executable scripts and arguments |
Date: |
Tue, 9 Feb 2010 01:21:56 -0800 (PST) |
David Grundberg-3 wrote:
>
>
> There is a limitation in how shebang interpretation works, like you
> discovered. This is documented in the Octave manual:
>
> http://www.gnu.org/software/octave/doc/interpreter/Executable-Octave-Programs.html#Executable-Octave-Programs
>
> Either that or use
>
> #!/usr/bin/octave -f
>
> and add a 'keyboard' call at the end of the script.
>
If I add a 'keyboard' in the script, I get
keyboard: stopped in ./myscript.m
panic: Segmentation fault -- stopping myself...
attempting to save variables to `octave-core'...
save to `octave-core' complete
zsh: segmentation fault ./myscript.m
This is what I get at the end of a trace obtained by running the script
through strace:
write(2, "keyboard: ", 10) = 10
write(2, "stopped in ./myscript.m", 25) = 25
write(2, "\n", 1) = 1
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
futex(0x1c6f8c0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
write(2, "panic: ", 7) = 7
write(2, "Segmentation fault", 18) = 18
write(2, " -- stopping myself...\n", 23) = 23
write(2, "attempting to save variables to "..., 49) = 49
open("octave-core", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
write(2, "save to `octave-core' complete\n", 31) = 31
write(3, "Octave-1-L\0\10\0\0\0.nargin.\0\0\0\0\0\377\6\0\0"..., 113) = 113
close(3) = 0
rt_sigaction(SIGSEGV, {SIG_DFL, [], SA_RESTART}, {0x628440, [], SA_RESTART},
8) = 0
tgkill(13211, 13211, SIGSEGV) = 0
sigreturn() = ? (mask now [])
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
This script just contains
#!/usr/bin/octave --no-init-file
keyboard
I alleviated the problem by using a 'pause', which does not create a panic.
Here is the beginning of the script:
%# check if we're in standalone mode
arg_list = strfind(argv(), 'myscript.m');
status = 0;
for i = 2:size(oper, 1),
if ~isempty(oper{i}),
status = 1
break;
endif
endfor
if status,
function bye_bye ()
disp ("Bye bye. Press any key to close this window.");
pause
endfunction
atexit ("bye_bye");
endif
It just iterates over argv(), and try to determine if the second argument
contains the script name. This second argument will usually be a longer
string, with either a relative or an absolute pathname. This way there is a
chance to read what the last error message was, before the window disappear.
Regards
Pascal
--
View this message in context:
http://old.nabble.com/executable-scripts-and-arguments-tp27499665p27512445.html
Sent from the Octave - General mailing list archive at Nabble.com.