Friday, April 1, 2011

Re: Problems using value returned by external command

On 02/04/11 03:57, Spiros Bousbouras wrote:
> The following on GNU/Linux with vim version 7.1
>
> prompt> cat myscript
> #!/bin/sh
> echo 1
>
> prompt> cat myscript.vim
> function! Check()
> let l:r = system("./myscript")
> if l:r == "1"
> echo "Good"
> else
> echo "Length of l:r is" strlen(l:r)
> echoerr "l:r is" l:r
> endif
> endfunction
>
> I start a vim session and do
>
> :source myscript.vim
> :echo Check()
>
> and get
>
> Length of l:r is 2
> Error detected while processing function Check:
> line 6:
> l:r is 1^@
> 0
>
> Replacing inside Check()
> if l:r == "1"
> with
> if l:r == "1\000"
> doesn't make any difference.
>
> Is this a bug ?
>

I don't know if it's a bug or a feature, but here I get the following:

:echo (system('echo 1') == "1")
0
:echo (system('echo 1') == "1\000")
0
:echo (system('echo 1') == 1
1
:echo (system('echo 1 2 3') == 1
1

Note that in the latter two cases, Vim's string-to-integer conversion
steps in.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
43. You tell the kids they can't use the computer because "Daddy's got
work to
do" and you don't even have a job.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment