Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何从ionic3应用程序运行系统命令? 什么?我想在Linux上运行Chromium应用程序的命令(或者将来可能运行Windows或Android) 为什么??例如,通过cec客户端等控制一些音频/电视设备 然而,围绕炮击、繁殖命令这一概念的问题是通用的_Angular_Linux_Typescript_Cordova_Ionic3 - Fatal编程技术网

Angular 如何从ionic3应用程序运行系统命令? 什么?我想在Linux上运行Chromium应用程序的命令(或者将来可能运行Windows或Android) 为什么??例如,通过cec客户端等控制一些音频/电视设备 然而,围绕炮击、繁殖命令这一概念的问题是通用的

Angular 如何从ionic3应用程序运行系统命令? 什么?我想在Linux上运行Chromium应用程序的命令(或者将来可能运行Windows或Android) 为什么??例如,通过cec客户端等控制一些音频/电视设备 然而,围绕炮击、繁殖命令这一概念的问题是通用的,angular,linux,typescript,cordova,ionic3,Angular,Linux,Typescript,Cordova,Ionic3,我已经整理了下面的SystemCall类,其中包含了我从不同帖子中找到的几次尝试,但是我遇到了这个错误“找不到模块”child\u process“ 我知道你不应该运行来自JS/TS的系统调用,但是这个应用程序将在受控环境中运行 希望我不需要本地服务器或PHP,但是如果你认为你有一个解决方案,我当然会考虑。我需要对本地硬件进行调用,而不是在远程服务器上调用。 我被Ionic3困住了太多突破性的变化,无法移动到Ionic5 我目前正在将SystemCall注入app.component.ts并

我已经整理了下面的SystemCall类,其中包含了我从不同帖子中找到的几次尝试,但是我遇到了这个错误“找不到模块”child\u process“

  • 我知道你不应该运行来自JS/TS的系统调用,但是这个应用程序将在受控环境中运行
  • 希望我不需要本地服务器或PHP,但是如果你认为你有一个解决方案,我当然会考虑。我需要对本地硬件进行调用,而不是在远程服务器上调用。
  • 我被Ionic3困住了太多突破性的变化,无法移动到Ionic5
我目前正在将SystemCall注入app.component.ts并调用SystemCall.Run()进行测试

奇怪的是,当我将鼠标悬停在导入行上时,VSCode会显示exec等的签名??

我已经运行了命令

npm install child_process --save
我的包裹现在显示出来了


感谢您的帮助,现在我正在浑水摸鱼。

您不能像在混合客户端应用程序中那样运行系统调用,因为代码是在web视图中执行的


也许可以使用Cordova插件,例如。

不幸的是,它看起来像Cordova插件shell exec.只适用于Android,因此它不能与当前的目标Linux平台一起工作。我想知道如何使用file-saver.js在Windows7上的硬盘上读写文件,这不在“webview”之外吗"? webview是他们所说的在浏览器的“沙箱”中运行的吗?感谢您花时间解释。是的,您可以将webview视为沙箱浏览器。所有浏览器都已允许下载文件或选择要上载的文件。但这需要从用户操作开始。但在普通浏览器应用程序上,您无法执行shell命令

// 
//----------------------------------------------------------------------
// FRAMEWORKS IMPORTS
//----------------------------------------------------------------------
import { Injectable } from '@angular/core' // 20160731
//
import { exec, ChildProcess, execSync} from 'child_process'
// import * as child from 'child_process';
//
//
//----------------------------------------------------------------------
// JS LIBRARY
//----------------------------------------------------------------------
// declare var plyr: any; // Magic makes JS variable available to TS :)
// declare var execSync 
//
/** - 20200607 */
@Injectable()
export class SystemCall {

    constructor(
        public ChildProcess: ChildProcess,

    ) {

    }

    Run() {
        this.Shell('notepad.exe')
        // this.Run1()
    }

    // https://stackoverflow.com/questions/5321884/how-do-i-run-the-system-commands-in-javascript
    Run0() {
        var spawn = require('child_process').spawn
        var Run = spawn('ls', ['-l']);
        // let Run = spawn('notepad.exe', [])
        Run.stdout.on('data', function (data) {
            console.log(data);
        });
    }

    Run1() {
        const { exec } = require("child_process");

        exec("dir", (error, stdout, stderr) => {
            if (error) {
                console.log(`error: ${error.message}`);
                return;
            }
            if (stderr) {
                console.log(`stderr: ${stderr}`);
                return;
            }
            console.log(`stdout: ${stdout}`);
        });
    }


    // https://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-javascript/52575123#52575123
    Run3() {
        const execSync = require('child_process').execSync;
        // import { execSync } from 'child_process';  // replace ^ if using ES modules
        const output = execSync('notepad.exe', { encoding: 'utf-8' });  // the default is 'buffer'
        console.log('Output was:\n', output);
    }

    // https://stackoverflow.com/questions/36546860/require-nodejs-child-process-with-typescript-systemjs-and-electron
    Run4() {
        // var foo: child.ChildProcess = child.exec('notepad.exe');
        // console.log(typeof foo.on);
    }

    // https://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-javascript/31897900#31897900
    /**
     * Execute simple shell command (async wrapper).
     * @param {String} cmd
     * @return {Object} { stdout: String, stderr: String }
     */
    async Shell(cmd) {
        return new Promise(function (resolve, reject) {
            exec(cmd, (err, stdout, stderr) => {
                if (err) {
                    reject(err);
                } else {
                    resolve({ stdout, stderr });
                }
            });
        });
    }

    async  Run5() {
        let stdout = await this.Shell('cmd.exe /c dir')
        for (let line of stdout.toString().split('\n')) {
            console.log(`ls: ${line}`);
        }
    }

}
npm install child_process --save