Node.js opens a local file, the file name contains special characters and cannot be opened

The project requirement is to open the file directly after downloading an excel and start writing the following method

openEXCEL(){
//this.bomoutput is the path where the file is stored locally
// First test whether there is this.bomoutput file
      myUtils.haveFile(this.bomoutput,(d)=>{
        if(d){
// If there is, you can execute the open operation with a single command, but it is not successful. Later, various attempts were made because of the special character "()" in the file name, because you tried to open without special characters.
          childProcess.exec(`${this.bomoutput}`, { encoding: 'binary' },(err,stdout,stderr)=>{
            if(stdout){
              console.log("stdout");
              console.log(this.iconv.decode(stdout, 'cp936'))
            } else {
            } 
            this.dialogFinishBomVisible=false;
          })
        }
      })
    },
Solution: add "" to the transmission path, as a whole, you can now directly open the file with special characters
childProcess.exec(` "${this.bomoutput}"`, { encoding: 'binary' },(err,stdout,stderr)=>{
            if(stdout){
              console.log("stdout");
              console.log(this.iconv.decode(stdout, 'cp936'))
            } else {
            } 
            this.dialogFinishBomVisible=false;
          })
 

Guess you like

Origin www.cnblogs.com/shanxinxin/p/12753303.html