Launch and executable file inside an Erlang Program

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

Launch and executable file inside an Erlang Program

Håkan Stenholm-2
Why not use os:cmd/1, this will run a.out or any other
command/application in unix.


Reply | Threaded
Open this post in threaded view
|

Launch and executable file inside an Erlang Program

Salvador Alcaraz

The complete sintax of os:cmd/1 is:


CommandOut = os:cmd(command),

for example:

CommandOut = os:cmd("ls"),

execute the 'ls' command (I think, in background) and return the result as
a string.


I need that the command/application opens a new shell, execute its
instrucctions and when finish, it close the shell and return to Erlang
program.


Is it possible?

Thank you

salva



On Sat, 30 Jun 2001, H?kan Stenholm wrote:

> Why not use os:cmd/1, this will run a.out or any other
> command/application in unix.
>




Reply | Threaded
Open this post in threaded view
|

Launch and executable file inside an Erlang Program

Vance Shipley-2
> I need that the command/application opens a new shell, execute its
> instrucctions and when finish, it close the shell and return to Erlang
> program.

Which is exactly what os:cmd/1 does.  From the Kernel Refernce Manual
in the section on the os module:
------------------------------------------------------------------------
cmd(Command) -> string()
       
        Types:
                Command = string() | atom()

        Executes Command in a command shell of the target OS and returns
        the result as a string.
------------------------------------------------------------------------

The emulator will spawn an operating system shell in a new process and
feed it the commands you gave it:

        1> os:cmd("pwd; times; echo $SHELL").
        "/export/home/vances\n0m0s 0m0s\n/bin/ksh\n"

  -Vance

Vance Shipley
Motivity Telecom Inc.
+1 519 579 5816


Reply | Threaded
Open this post in threaded view
|

Launch and executable file inside an Erlang Program

Daniel Neri
In reply to this post by Håkan Stenholm-2
H?kan Stenholm <hokan.stenholm> writes:

> Why not use os:cmd/1, this will run a.out or any other
> command/application in unix.

While on the subject, apparently os:cmd/1 still has problems with
binary output (on Unix), as I noted some time ago[*].


Regards,
   --Daniel


[*] http://www.erlang.org/ml-archive/erlang-questions/200101/msg00127.html

--
Daniel Neri
dne


Reply | Threaded
Open this post in threaded view
|

Launch and executable file inside an Erlang Program

Salvador Alcaraz
In reply to this post by Vance Shipley-2

I think that Daniel Neri is right:

"...apparently os:cmd/1 still has problems with
binary output (on Unix)".

because, what does happen if execute an application with E/S display
instructions??

For example:

 1> os:cmd("pine").  


Thank you in advance

salva



On Sat, 30 Jun 2001, Vance Shipley wrote:

> > I need that the command/application opens a new shell, execute its
> > instrucctions and when finish, it close the shell and return to Erlang
> > program.
>
> Which is exactly what os:cmd/1 does.  From the Kernel Refernce Manual
> in the section on the os module:
> ------------------------------------------------------------------------
> cmd(Command) -> string()
>
> Types:
> Command = string() | atom()
>
> Executes Command in a command shell of the target OS and returns
> the result as a string.
> ------------------------------------------------------------------------
>
> The emulator will spawn an operating system shell in a new process and
> feed it the commands you gave it:
>
> 1> os:cmd("pwd; times; echo $SHELL").
> "/export/home/vances\n0m0s 0m0s\n/bin/ksh\n"
>
>   -Vance
>
> Vance Shipley
> Motivity Telecom Inc.
> +1 519 579 5816
>



Reply | Threaded
Open this post in threaded view
|

Launch and executable file inside an Erlang Program

Matthias Lang-2
Salvador Alcaraz writes:
 >
 > I think that Daniel Neri is right:
 >
 > "...apparently os:cmd/1 still has problems with
 > binary output (on Unix)".
 >
 > because, what does happen if execute an application with E/S display
 > instructions??
 >
 > For example:
 >
 >  1> os:cmd("pine").  

What should erlang do in this situation? Return the escape sequences
as a string when 'pine' exits. Not terribly useful. What you probably
want it to do is to take over the terminal and run 'pine' until the
user quits pine. This seems fraught with problems.

A cheesy (or clean, depending on your point of view) way to avoid the
problem on X is

  2> os:cmd("xterm -e pine").

Messing around with open_port({spawn, "pine"}, ...) and taking care of
the io seems impossibly hairy. Trying to get the sub-process to take
over the terminal (using {fd, 0, 1}) might be an option if you can
live without ^G and ^C and IO for other erlang processes, but I can't
figure out the details of getting this to fly (-noshell doesn't seem
to be enough).

Matthias