node.js
  • cordova
  • child-process
  • spawn
  • 2017-10-18 112 views 1 likes 
    1

    我試圖用目標設備啓動cordova命令。我測試過這個命令並且它可以工作,但是當我嘗試用我的代碼生成它時,它忽略了等號,因此不會運行。此代碼確實與另外的"--target='iPhone-7-Plus"node.js child_process spawn忽略等號

    return new Promise((resolve, reject) => { 
        const executable = "ionic"; 
        const arguments = [ 
        "cordova", 
        buildOnly ? "build" : "run", 
        platform, 
        "--no-interactive", 
        "--verbose", 
        "--target='iPhone-7-Plus'" 
        ].concat(releaseDev === "release" ? ["--prod", "--release"] : []); 
        console.log(executable, arguments.join(" ")); 
        const child = spawn(executable, arguments, { 
        stdio: "inherit" 
        }); 
        child.on("close",() => resolve()); 
        child.on("error", err => reject(err)); 
    }); 
    

    我在做什麼錯在這裏工作,只是沒有?爲什麼它只會忽略我的等號,但其餘的命令會被添加?

    如果我運行cordova run ios --target='iPhone-7-Plus'該命令將執行並啓動7+模擬器,而不會出現問題。

    +0

    我在該行看到''--target ='iphone-7-plus「',這可能是問題嗎? –

    +0

    @DavidGatti我不好,我抄了錯。在我的代碼中它確實有'''和runnning'cordova運行ios --target ='iPhone-7-Plus''直接輸入到命令行時沒有問題執行。 –

    +0

    我建議您更新問題。那麼在數組'buildOnly中刪除這個if else語句形式呢? 「構建」:「運行」,「一些核心的方法去做這件事,我也會做'console.log'的console.log,然後再傳遞給Spaw,看看它是如何處理你在那裏的操作。 –

    回答

    1

    當產卵時,我不得不添加shell: true爲了使用我的操作系統的默認外殼。產卵使用的外殼將去除特殊字符。

    const child = spawn(executable, arguments, { 
        stdio: "inherit", 
        shell: true 
    }); 
    
    相關問題