简体   繁体   中英

How to pass arguments into erlang os:cmd()?

I want to know how to pass arguments into shell script when use ErLang? I know I can use os:cmd() to execute shell script, but I find I can't pass arguments into this command.

For example, I have one argument L = 2 , and I want my shell script use this argument, so the erlang command should be os:cmd("bash echo.sh L") . However, the output is L, but I want to get 2 instead. Can anyone help me?

The function io_lib:format/2 allow you to prepare a string and then pass it to os:command/1 :

S = io_lib:format("bash echo.sh ~p",[L]),
os:cmd(S),

S is a nested list, I don't remember if it is accepted by os:cmd/1 , if not you will have to flatten the result os:cmd(lists:flatten(S))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM