Page 1 of 1

When command-line arguments contain "http://" something ....

Posted: Sun Jan 20, 2013 10:38 am
by winger
create a empty file a.lsp

Code: Select all

winger@winger$ newlisp a.lsp http://www.google.com/bank.html

ERR: problem accessing file : "ERR: server code 404: HTTP/1.1 404 Not Found\r\n<!DOCTYPE html>\n<html lang=en>\n  <meta charset=utf-8>\n  <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n  <title>Error 404 (Not Found)!!1</title>\n  <style>\n    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{back
so xxxxx.
I can not use the parameter contains "http://" because newlisp automatically get url data.
Maybe we can set special parameters to deal with the problem. ?

Re: When command-line arguments contain "http://" something

Posted: Sun Jan 20, 2013 7:02 pm
by Lutz
The empty file a.lsp has nothing to with what you see ;-) The second part of the error message is what the server returns to you and might be useful to analyze the error. It may also be different for any server you talk to.

You could suppress the second part of the error message for just that type of error by loading the following function first or put it into .init.lsp in your home directory on both Windows and Unix:

Code: Select all

(error-event (fn () 
    (if (= 4 ((last-error) 0)) 
        (println "ERR:" (last (last-error 4))) 
        (println ((last-error) 1)))))
This function will get called whenever and error occurs. For all load errors then, the second part of the eror text will be suppressed:

Code: Select all

~> newlisp http://newlisp.org/example.foobar
ERR:problem accessing file
newLISP v.10.4.5 on OSX IPv4/6 UTF-8 libffi, execute 'newlisp -h' for more info.

> ^D
~> newlisp http://newlisp.org/example.lsp
A happy new year to all newLISP users ( and to everybody else too :-) )
~> 

Re: When command-line arguments contain "http://" something

Posted: Sat Jan 26, 2013 2:24 am
by winger
i just want get "http://www.google.com/bank.html" as a text argument.
(last-error) can't get the url.

Of course we can pass parameter as this :

Code: Select all

newlisp a.lsp  www.google.com/bank.html
Then add prefix in the code.

Code: Select all

(setf url (string "http://" (main-args -1)))
这不和谐啊

Re: When command-line arguments contain "http://" something

Posted: Sat Jan 26, 2013 3:54 am
by bairui
An only slightly more harmonious solution might be to go the other way and expect URL literal command-line arguments to be marked up so as to prevent them being remotely executed by newLISP. Prepending a + is one simple way:

Code: Select all

newlisp +http://www.google.com/bank.html
getting the url then as:

Code: Select all

(setf url (1 ((main-args) -1)))
This is only slightly better in that it doesn't assume the protocol is always http.