javascript (spidermonkey) how does one run a linux command from js shell?

后端 未结 5 504
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-20 04:17

I\'m stumped and feeling stupid. I\'ve tried every search combination I can think of to figure this out. It seems simple, but being new to javascript I\'m not seeing anythin

5条回答
  •  情话喂你
    2021-01-20 04:42

    Ok, I'm feeling less stupid now. I got it working using Jscript and the jsc.exe included with the .NET Framework on Windows:

    > var myFileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
    > 
    > var pathToFileDir = ".";
    > var myFolder = myFileSystemObj.GetFolder(pathToFileDir);
    > 
    > var myEnum = new
    > Enumerator(myFolder.Files);
    > 
    > for
    > (;!myEnum.atEnd();myEnum.moveNext()) {
    >   print(myEnum.item()) }
    

    which gives me the file names in a directory nice and easy on the ol' XP. So I guess the question should be is there a similar facility for doing this on Linux? I'm trying to recompile the Spidermonkey engine with the JS_HAS_FILE_OBJECT=1 flag, but it errors out, so I have some reading & work ahead of me to get this working, but I think I'm heading in the right direction. Any hints or suggestions on a different way to do this with javascript would be welcome (beyond "use N", where N = python, perl, java, etc...).

提交回复
热议问题