Piping Vim Variables to Shell Execution

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Piping Vim Variables to Shell Execution

Alejandro Calbazana
Hello,

Can anyone help me with how to pipe a variable (in this case a
classpath) to shell execution.  For example:

:!echo expand('$CLASSPATH')

:!java -cp expand('$CLASSPATH') MyClass

Since the context of my project is already set up, I'd hate to have to
open a shell and retype the classpath :)

Thanks,

Alejandro
Reply | Threaded
Open this post in threaded view
|

Re: Piping Vim Variables to Shell Execution

David Rennalls
On 8/31/05, Alejandro Calbazana <[hidden email]> wrote:

> Hello,
>
> Can anyone help me with how to pipe a variable (in this case a
> classpath) to shell execution.  For example:
>
> :!echo expand('$CLASSPATH')
>
> :!java -cp expand('$CLASSPATH') MyClass
>
> Since the context of my project is already set up, I'd hate to have to
> open a shell and retype the classpath :)
>
> Thanks,
>
> Alejandro

Try creating the full command string and then passing it to :exe
for e.g.
:exe '!java -cp' . expand('$CLASSPATH') . ' MyClass'

- David
Reply | Threaded
Open this post in threaded view
|

Re: Piping Vim Variables to Shell Execution

A.J.Mechelynck
In reply to this post by Alejandro Calbazana
----- Original Message -----
From: "Alejandro Calbazana" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, August 31, 2005 9:04 PM
Subject: Piping Vim Variables to Shell Execution


> Hello,
>
> Can anyone help me with how to pipe a variable (in this case a
> classpath) to shell execution.  For example:
>
> :!echo expand('$CLASSPATH')
>
> :!java -cp expand('$CLASSPATH') MyClass
>
> Since the context of my project is already set up, I'd hate to have to
> open a shell and retype the classpath :)
>
> Thanks,
>
> Alejandro

Since $CLASSPATH is an environment variable, what about

    :!java-cp $CLASSPATH MyClass

(using some Unix shell, if a space is needed between the two) or

    :!java-cp ${CLASSPATH}MyClass

(using bash shell, if no space is needed between the two) or

    :!java-cp \%CLASSPATH\%MyClass

(using COMMAND.COM or CMD.EXE shell)?

Warning: all the above are untested: try them first with :!echo


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: Piping Vim Variables to Shell Execution

Mikołaj Machowski
In reply to this post by Alejandro Calbazana
Dnia ?roda, 31 sierpnia 2005 21:04, Alejandro Calbazana napisa?:
> Hello,
>
> Can anyone help me with how to pipe a variable (in this case a
>
> classpath) to shell execution.  For example:
> :!echo expand('$CLASSPATH')
> :
> :!java -cp expand('$CLASSPATH') MyClass
>

:help exe

:exe "!java -cp ".expand('$CLASSPATH')." MyClass"

HTH

m.