From: ··········@gmail.com
Subject: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <261f32c9-0d9b-4524-917f-793ec2fade74@s8g2000prg.googlegroups.com>
Hello all,

I'm rather new to Lisp, but work with some seasoned pros. Each of them
tells me that I can't call a Python script from Lisp under Windows.
They can call any .exe, but no Python or even Perl. I find that really
hard to believe, but searching the Net, I can't find any tips either.
Any help here?

Thx,

D

From: Marco Antoniotti
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <06e972d2-bf02-4ef3-8256-b5d566749df9@k2g2000hse.googlegroups.com>
On Jan 11, 7:22 am, ···········@gmail.com" <··········@gmail.com>
wrote:
> Hello all,
>
> I'm rather new to Lisp, but work with some seasoned pros. Each of them
> tells me that I can't call a Python script from Lisp under Windows.
> They can call any .exe, but no Python or even Perl. I find that really
> hard to believe, but searching the Net, I can't find any tips either.
> Any help here?
>
> Thx,
>
> D

Why can't you do something like in LWW

    (system:call-system "python script.py")

?

Other CLs have different commands, but they all allow running the
Python interpreter, to which you pass the script.

Cheers
--
Marco
From: vanekl
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <3afbf013-3c64-4366-971a-fe1dd9824320@v29g2000hsf.googlegroups.com>
Your colleagues are correct if they were referring to no _standard_
way of running an external program. It's implementation dependent.
Check your Lisp manual.

Here's how I did it when I was working with Clisp on Windows and I
needed to access a Prolog executable called XSB (notice "run-shell-
command"):

;; This is not production-ready code.
(defparameter *prolog-exe* "c:/local/pl/bin/plcon.exe ")

(defun exec-xsb-query (query)
  (let* ((extension "PL") ; keep all extensions uppercase since LISP
tends to make them so when creating pathnames
	 (filenm  (make-temporary-pathname extension))
	 (filenm_no_type (subseq (namestring filenm) 0 (- (length (namestring
filenm)) (+ 1 (length extension)))))
	 stream
	 (app *prolog-exe*)
	 (args (format nil " -f none -g \"load_files(['c:/cygwin~a.~a'],
[silent(true)])\" -t start" filenm_no_type extension))
	 (cmd (string-append app  args))
	 (prolog-pgm (format nil "start :- load_files('c:/dev/prolog/r/r',
[silent(true)]), ldb, assert_db, ~a, write(A).~% " query)))
    ;; The following two lines of code can be ignored;
    ;; they are not necessary if all you need to do is
    ;; run an external program.
    (with-open-file (stream filenm :direction :output :if-
exists :supersede)
      (format stream prolog-pgm))
    (setf stream (run-shell-command cmd	:output :stream))
    (let ((output
	   (loop for line = (read-line stream nil nil)
		 while line collect line
		 do (format t "line: ~a" line))))  ;; dbg
      output)))

--
Real programmers can write Fortran in any language.
From: Duane Rettig
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <o063y0uz7x.fsf@gemini.franz.com>
···········@gmail.com" <··········@gmail.com> writes:

> Hello all,
>
> I'm rather new to Lisp, but work with some seasoned pros. Each of them
> tells me that I can't call a Python script from Lisp under Windows.
> They can call any .exe, but no Python or even Perl. I find that really
> hard to believe, but searching the Net, I can't find any tips either.
> Any help here?

Take a look at CLPython:

http://common-lisp.net/project/clpython/

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182   
From: Alex Mizrahi
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <47872ced$0$90262$14726298@news.sunsite.dk>
 d> I'm rather new to Lisp, but work with some seasoned pros.
 d>  Each of them tells me that I can't call a Python script from Lisp under
 d> Windows. They can call any .exe, but no Python or even Perl.

you need to call python.exe and pass yourscript.py (or a path to) as a first 
parameter.
so, you can use same method as you call exe, as long as you can pass 
parameters.

indeed Windows does not understand shebangs like #!/usr/bin/python, so it 
seems you cannot run script directly.
however, Windows supports executable extension associations, so it will know 
that it needs to run *.py via python.exe, i think that will work if you'll 
run python script through the shell and python is registered properly..

but the first method i've mentioned is prefered because it doesn't depend on 
these registrations. 
From: Tim Howe
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <873at457zx.fsf@rash.fl.quadium.net>
"Alex Mizrahi" <········@users.sourceforge.net> writes:

> you need to call python.exe and pass yourscript.py (or a path to) as a
> first parameter.

[...]

> however, Windows supports executable extension associations, so it
> will know that it needs to run *.py via python.exe, i think that will
> work if you'll run python script through the shell and python is
> registered properly..

You need to use the "START" command for that.

  (ext:run-program "START" '("c:\\foo\\bar\\baz.py"))  ; or so

"START /?" will give you all sorts of options.

I don't think you'll be able to capture stdout or stderr but I could be
wrong.

> but the first method i've mentioned is prefered because it doesn't depend on 
> these registrations. 

Depends on which sort of dependencies they wish to avoid, of course.

-- 
vsync
http://quadium.net/~vsync/

If language is not correct, then what is said is not what is meant; if
what is said is not what is meant, then what must be done remains
undone; if this remains undone, morals and art will deteriorate; if
justice goes astray, the people will stand about in helpless
confusion. Hence there must be no arbitrariness in what is said. This
matters above everything.
        -- Confucius
From: Victor Anyakin
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <86fxx4g33m.fsf@victor-mobi.my.domain>
···········@gmail.com" <··········@gmail.com> writes:

> Hello all,
>
> I'm rather new to Lisp, but work with some seasoned pros. Each of them
> tells me that I can't call a Python script from Lisp under Windows.
> They can call any .exe, but no Python or even Perl.

But then you can call either python or perl interpreter passing the
script file name as a parameter. Isn't it?

> I find that really hard to believe, but searching the Net, I can't
> find any tips either.  Any help here?
>
> Thx,
>
> D
From: Marco Antoniotti
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <51454a34-d8ea-4a81-ba5f-1ce6ef0adc2e@x69g2000hsx.googlegroups.com>
On Jan 11, 9:48 am, Victor Anyakin <······@victor-mobi.my.domain>
wrote:
> ···········@gmail.com" <··········@gmail.com> writes:
> > Hello all,
>
> > I'm rather new to Lisp, but work with some seasoned pros. Each of them
> > tells me that I can't call a Python script from Lisp under Windows.
> > They can call any .exe, but no Python or even Perl.
>
> But then you can call either python or perl interpreter passing the
> script file name as a parameter. Isn't it?

So?  Under UNIX it *seems* that you are running an executable file
just because you are sticking #!/wtf/perl/is/perl or #!/wtf/python/is/
python as the first line of your script.  In Windows you tell the OS
that .py files are to be executed with Python, i.e., that when you
execute a foo.py file you should really do python foo.py.  There is no
magic here: the interpreter must be called one way or the other.  The
- quote - problem - unquote - is that most CLs will probably try to
execute the "shell" (cmd.exe or, in more ancient times, command.com)
as a way to start an external command.  You just use that by calling
the interpreter and you are home free.

Cheers
--
Marco
From: Victor Anyakin
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <86y7awjv3s.fsf@victor-mobi.my.domain>
Marco Antoniotti <·······@gmail.com> writes:

> On Jan 11, 9:48�am, Victor Anyakin <······@victor-mobi.my.domain>
> wrote:
>> ···········@gmail.com" <··········@gmail.com> writes:
>> > Hello all,
>>
>> > I'm rather new to Lisp, but work with some seasoned pros. Each of them
>> > tells me that I can't call a Python script from Lisp under Windows.
>> > They can call any .exe, but no Python or even Perl.
>>
>> But then you can call either python or perl interpreter passing the
>> script file name as a parameter. Isn't it?
>
> So?  Under UNIX it *seems* that you are running an executable file
> just because you are sticking #!/wtf/perl/is/perl or #!/wtf/python/is/
> python as the first line of your script.  In Windows you tell the OS
> that .py files are to be executed with Python, i.e., that when you
> execute a foo.py file you should really do python foo.py.  There is no
> magic here: the interpreter must be called one way or the other.

Actually yes.  But, IMHO: one more difference is that .py or
.what-ever-files on UNIX tell what to execute themselves, including
command-line options and so on.  These shebang clauses can even
specify which interpreter version to use: either the 2.1 one, or the
5.10, or the version you've installed in your home directory.

However, setting up and association between .py files and python.exe
on Windows is no magic at all, but it does not provide the same
flexibility as shebang on UNIX.

With best regards,

Victor
From: Jean Guillaume Pyraksos
Subject: Re: Calling a Python script from Lisp under Windows XP.
Date: 
Message-ID: <wissme-BD440F.11163213012008@news.free.fr>
In the same vein, does someone script Blender from Lisp ?

    -JG