Node.JS on Windows: how to fix error spawn child process don’t work with the quotes


Example code:

        const subprocess = spawn("C:\\Windows\\aria2c.EXE", [
            '--file-allocation=none',
            '--header="Cookie:DRIVE_STREAM=pLN8Qew1jVg;"',
            "-c",
            "-j5", 
            "-d",
            "C:\\Users\\Administrator",
            "-x5", 
            "-o", 
            "downloaded."+b+".mp4", 
            linkarr[0]["link"]
        ], {
          detached: true,           
          stdio: [ 'ignore', out, err ]
        });

This process run unsucessfully, cause the quotes is escaped. So, you must use option: windowsVerbatimArguments

        const subprocess = spawn("C:\\Windows\\aria2c.EXE", [
            '--file-allocation=none',
            '--header="Cookie:DRIVE_STREAM=pLN8Qew1jVg;"',
            "-c",
            "-j5", 
            "-d",
            "C:\\Users\\Administrator",
            "-x5", 
            "-o", 
            "downloaded."+b+".mp4", 
            linkarr[0]["link"]
        ], {
          detached: true,
          windowsVerbatimArguments: true,
          stdio: [ 'ignore', out, err ]
        });

Leave a Reply