lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Hongyi Zhao once stated:
> 
> Run the following script under terminal:
> 
> obtain-script-path.lua
> -------
> cmd = os.execute("pwd") and "pwd" or "cd"
        ^^^^^^^^^^^^^^^^

This is excuting the command "pwd", and the output will go to stdout.

> f = io.popen(cmd,"r")
      ^^^^^^^^^^^^^^^^

This is also executing the command "pwd", only the output will be piped to
Lua.

> path = f:read("*a")
> f:close()
> 
> print(path)
> ------
> 
> Will give me the following output:
> 
> $ lua obtain-script-path.lua
> /home/werner/Public/Lmod
> /home/werner/Public/Lmod
> 
> As you can see, the script print the path twice, but I only used one
> print command.  How to disable the other one output line?

  You can either just set cwd to "pwd", or

	os.execute("pwd >/dev/null") -- adjust according to OS

But that sill executes the command twice.

  -spc