`
mryufeng
  • 浏览: 977629 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

how to call os:cmd("ls") from shell?(老掉牙问题)

阅读更多
之前erlang邮件列表的一个问题:

hi list,

I fellowed the otp document, but it failed.

# erl -s os cmd ls

Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0] [hipe]
[kernel-poll:false] [lock-checking]

{"init terminating in
do_boot",{function_clause,[{os,validate1,[[ls]]},{os,cmd,1},{init,start_it,1},{init,start_em,1}]}}

Crash dump was written to: erl_crash.dump


Thx,
Jeremy
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply

Reply to all

Forward


yerl@club-internet.fr to erlanging, erlang-questio.

show details 7/11/07



Reply


echo 'os:cmd("ls").' | erl

cheers
Y.

----Message d'origine----
>Date: Wed, 11 Jul 2007 14:06:43 +0800
>De: "Jeremy Chow" <erlanging@gmail.com>
>A: erlang-questions@erlang.org
>Sujet: [erlang-questions] how to call os:cmd("ls") from shell?
- Show quoted text -
>
>hi list,
>
>I fellowed the otp document, but it failed.
>
># erl -s os cmd ls
>
>Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0] [hipe]
>[kernel-poll:false] [lock-checking]
>
>{"init terminating in
>do_boot",{function_clause,[{os,validate1,[[ls]]},{os,cmd,1},{init,start_it,1},{init,start_em,1}]}}
>
>Crash dump was written to: erl_crash.dump
>
>
>Thx,
>Jeremy
>_______________________________________________
>erlang-questions mailing list
>erlang-questions@erlang.org
>http://www.erlang.org/mailman/listinfo/erlang-questions
>

_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply

Reply to all

Forward


Bengt Kleberg to erlang-questio.

show details 7/11/07



Reply


On 2007-07-11 08:06, Jeremy Chow wrote:
> hi list,
>
> I fellowed the otp document, but it failed.
>
> # erl -s os cmd ls

this will not work.
1 erl -s will bundle the arguments (ls) into a list as atoms.
       os:cmd( [ls] ).
2 os:cmd/1 wants a string. os:cmd("ls").


one might think that
erl -run os cmd ls
will work since -run keeps the arguments as strings, but -run also
bundles all arguments into a single string.

so you have to write an interface module that calls os:cmd/1 for you.


bengt
--
Those were the days...
   EPO guidelines 1978: "If the contribution to the known art resides
   solely in a computer program then the subject matter is not
   patentable in whatever manner it may be presented in the claims."
- Show quoted text -

参见init 文档:

-eval Expr
    Scans, parses and evaluates an arbitrary expression Expr during system initialization. If any of these steps fail (syntax error, parse error or exception during evaluation), Erlang stops with an error message. Here is an example that seeds the random number generator:

    % erl -eval '{X,Y,Z}' = now(), random:seed(X,Y,Z).'

    This example uses Erlang as a hexadecimal calculator:

    % erl -noshell -eval 'R = 16#1F+16#A0, io:format("~.16B~n", [R])' \
    -s erlang halt
    BF
           

    If multiple -eval expressions are specified, they are evaluated sequentially in the order specified. -eval expressions are evaluated sequentially with -s and -run function calls (this also in the order specified). As with -s and -run, an evaluation that does not terminate, blocks the system initialization process.
-extra
    Everything following -extra is considered plain arguments and can be retrieved using get_plain_arguments/0.
-run Mod [Func [Arg1, Arg2, ...]]
    Evaluates the specified function call during system initialization. Func defaults to start. If no arguments are provided, the function is assumed to be of arity 0. Otherwise it is assumed to be of arity 1, taking the list [Arg1,Arg2,...] as argument. All arguments are passed as strings. If an exception is raised, Erlang stops with an error message.
    Example:

    % erl -run foo -run foo bar -run foo bar baz 1 2

    This starts the Erlang runtime system and evaluates the following functions:

    foo:start()
    foo:bar()
    foo:bar(["baz", "1", "2"]).
           

    The functions are executed sequentially in an initialization process, which then terminates normally and passes control to the user. This means that a -run call which does not return will block further processing; to avoid this, use some variant of spawn in such cases.
-s Mod [Func [Arg1, Arg2, ...]]
    Evaluates the specified function call during system initialization. Func defaults to start. If no arguments are provided, the function is assumed to be of arity 0. Otherwise it is assumed to be of arity 1, taking the list [Arg1,Arg2,...] as argument. All arguments are passed as atoms. If an exception is raised, Erlang stops with an error message.
    Example:

    % erl -s foo -s foo bar -s foo bar baz 1 2

    This starts the Erlang runtime system and evaluates the following functions:

    foo:start()
    foo:bar()
    foo:bar([baz, '1', '2']).
           

    The functions are executed sequentially in an initialization process, which then terminates normally and passes control to the user. This means that a -s call which does not return will block further processing; to avoid this, use some variant of spawn in such cases.
    Due to the limited length of atoms, it is recommended that -run be used instead.

还可以这样:
erl -noshell -eval 'os:cmd("ls").' -s init stop


但是因为没有shell所以目录的内容没有被列出来。

貌似没有最好的方案!!!

分享到:
评论
2 楼 xiaolin0105 2008-02-05  
我不想再碰erlang了。。。
1 楼 jackyz 2008-02-05  
但是因为没有shell所以目录的内容没有被列出来。

erl -noshell -eval 'io:format("~s", [os:cmd("ls")]).' -s init stop

貌似是没有打印?

相关推荐

    大学体验英语答案(完整版)level 3

    1 "Lu Yi: How do you do? Dick: How do you do? Lu Yi: My name is Lu Yi. Dick: I'm Richard Green. Please call me Dick. Lu Yi: Glad to meet you. Dick: Nice to meet you, too." 2 "Zhou Ming: Excuse me, ...

    「安全认证」How to Get Promoted:Developing Metrics to Show How Thre

    「安全认证」How to Get Promoted:Developing Metrics to Show How Threat Intel Works - 恶意软件 数据安全 防火墙 身份管理 安全体系 安全漏洞

    英语特殊疑问句练习带答案..doc

    这些练习旨在帮助学习者掌握使用特殊疑问词(如what, who, where, when, why, how等)提问的正确方法,以及理解在不同情境下如何回应这些问题。通过反复练习,能有效提升英语口语交流能力,同时加深对特殊疑问句结构...

    英语-特殊疑问句练习题(附答案).doc

    8. "I am from Hubei." 提问:Where are you from? 9. "I went to school late because I got up late." 提问:Why were you late for school? 10. "It is windy." 提问:What's the weather like? 11. "I am ...

    小学英语句型转换练习.pdf

    1. 一般疑问句:Do you go to school from Monday to Friday? 否定回答:No, I don't. 2. 一般疑问句:Do you like to go to school very much? 肯定回答:Yes, we do. 3. 一般疑问句:Do they usually have lunch ...

    人教版七年级英语下册英语复习提纲.doc

    + How can I get to ……?:我怎样到达……呢? + Is there …… near here / in the neighborhood?:附近有……吗? + Which is the way to ……?:哪条是去……的路? * Showing the ways: + Go straight ...

    Multimedia on Symbian OS: Inside the Convergence Device

    Additional information includes the evolution of multimedia on Symbian OS from previous versions to the current (v9.5) and plans for the future. Chapters include: Architecture of Multimedia on ...

    六年级英语上册期末练习题10精选.doc

    3. 提问:How are you going to the Great Wall? 回答:I’m going there by subway. 4. 提问:Are you going to the library? 回答:No, I am going to the cinema. 5. 提问:Does your sister like watching ...

    how to block call in CUCM

    call-block translation-profile incoming call_blocktranslated incoming called-number .direct-inward-dial port 0/0/0:23 ``` 4. **测试翻译规则**:为了确保规则生效,您可以使用以下命令测试翻译规则: ...

    小学同义句转换.pdf

    + It’s going to rain tomorrow. (同义句:It’s going to be rainy tomorrow. It will rain tomorrow. It will be rainy tomorrow.) * 描述感受: + I like to swim in the sea. (同义句:I like swimming in ...

    The_Inside_Threat_-_as_important_as_profits_.pdf

    How: how did the data go missing? Now it’s personal: Inside Threat, Risk and Governance Mitigating the Threat: what tools can help Summary The inside threat is very real. Even the most motivated, ...

    (PEP)人教版小学英语3_6年级常用表达法1.doc

    4. 见面问候:Nice to meet you. 回答:Nice to meet you, too. 5. 指示涂色:Colour it brown! Unit 3 Look at me! 1. 询问对方健康状况:How are you? 回答:I’m fine, thank you. 以及邀请上学:Let’s go to ...

    Common Design Patterns for Symbian OS: The Foundations of Smartphone Software

    While individual examples may come from one version or another the patterns outlined in this book are intended to be more generic and based on the common functionality available in all releases....

    小学英语特殊疑问句练习带答案.doc

    例如:"How far is it from your home to school?" (从你家到学校有多远?) - 练习题中:A: How far is it from here? B: It’s about two kilometres away. 以上就是特殊疑问句的基本用法及其在实际应用中的例子...

    firebreath source control and how to call js function

    在"firebreath source control and how to call js function"这个主题中,我们将深入探讨FireBreath的源码管理以及如何在C++插件中调用JavaScript函数。 首先,源码控制是软件开发中的关键部分,它确保了团队成员...

    小学三年级六年级英语学习主要知识点[2]-.pdf

    - 句型:How old are you? 用来询问年龄,回答形式如I’m 12。 2. **询问颜色**: - 句型:What colour is it? 对单一物体的颜色提问,回答It’s yellow and white等。 - 句型:What colour are they? 询问复数...

Global site tag (gtag.js) - Google Analytics