How to execute files without specifying a path.

As the title, I don't want to execute cmd in a specified or specific directory, but it can be executed no matter which directory I execute the file in.
How can it be modified?
out = fileread('1.txt');
cmd = ['xxx.exe', out];
system(cmd)
THX

回答 (1 件)

Bhaskar R
Bhaskar R 2019 年 12 月 9 日
編集済み: Bhaskar R 2019 年 12 月 9 日

0 投票

You can but
  1. Files shold be in present working directory
  2. Program(here xxx.exe) should set to environmental variable if it is not present in the present workind directory
Code
cmd = ['xxx.exe', ' ', '1.txt'];
system(cmd);

3 件のコメント

han han
han han 2019 年 12 月 9 日
I may not express it well enough. I mean that no matter where my xxx.exe is, it can be executed through matlab without adding a path in front. (Example: C: \ Users \ xxx.exe)
Bhaskar R
Bhaskar R 2019 年 12 月 9 日
Set xxx.exe as environmental variable, then execute your code
Walter Roberson
Walter Roberson 2019 年 12 月 9 日
You should add the directory containing the executable to the PATH environment variable.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

タグ

質問済み:

2019 年 12 月 9 日

コメント済み:

2019 年 12 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by