Skip to content

[bug] Can not use system base directory variables in shell cmd #5480

@ianho7

Description

@ianho7

Describe the bug

I want to use shell command api to run a executable file, here is my code:
`

const resourceDirPath = await resourceDir()
console.log(resourceDirPath = ${resourceDirPath})
const command = new Command('download', ['https://www.bilibili.com/video/BV1rP4y1U75S'])
command.on('close', (data) => {
  console.log(`command finished with code ${data.code} and signal ${data.signal}`)
})

command.on('error', (error) => console.error(`command error: "${error}"`))
command.stdout.on('data', (line) => {
  console.log(`command stdout: "${line}"`)
  if (line) {
    setLog(`${log}\n${line}`)
  }
})
command.stderr.on('data', (line) => console.log(`command stderr: "${line}"`))

const child = await command.spawn()
console.log('pid:', child.pid)

And here is my tauri.conf.json
"shell": { "all": true, "execute": true, "sidecar": true, "open": true, "scope": [{ "name": "download", "cmd": "$RESOURCE/sdk/you-get-darwin", "args": [{ "validator": "\\S+" }] }] }

This is result:
image

I check the resource directory(resourceDirPath = /Users/ianho/Documents/project/private/tauri-react-template/src-tauri/target/debug/
Index.tsx:61) and the executable file is exists.
image

Could you please tell my what's wrong with my code or the correct way to use tauri api, thank a lot!

Reproduction

No response

Expected behavior

No response

Platform and versions

Environment
› OS: Mac OS 12.3.1 X64
› Node.js: 16.13.0
› npm: 8.1.0
› pnpm: 7.13.5
› yarn: 1.22.10
› rustup: 1.25.1
› rustc: 1.64.0
› cargo: 1.64.0
› Rust toolchain: stable-x86_64-apple-darwin

Packages
› @tauri-apps/cli [NPM]: 1.1.1
› @tauri-apps/api [NPM]: 1.1.0
› tauri [RUST]: 1.0.5,
› tauri-build [RUST]: 1.0.4,
› tao [RUST]: 0.12.2,
› wry [RUST]: 0.19.0,

App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:3000/
› framework: React

App directory structure
├─ dist
├─ node_modules
├─ src-tauri
├─ .git
└─ src

Stack trace

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions