Sublime Forum

Why cannot use array of strings in shell_cmd in build systems

#1

Build Systems (sublimetext.com)

When formatting commands with massive arguments, array of string is helpful to format the strings.

0 Likes

#2

It will be passed to the shell, as is. Converting an array of string to a string depends on what the shell is.

0 Likes

#3

But in the exec.py in the bundled package, if the value is a array and it’s “cmd”, it simply just joins the strings, this could also be applied to shell_cmd

if shell_cmd:
print("Running " + shell_cmd)
elif cmd:
cmd_string = cmd
if not isinstance(cmd, str):
cmd_string = " ".join(cmd)
print("Running " + cmd_string)
sublime.status_message(“Building”)

0 Likes

#4

Hmm… Then the responsibility is on the user.

0 Likes

#5

But if cmd is simply concatenating them with a space, then why don’t you just use cmd?

0 Likes

#6

Emm, the key point is that “an array of strings helps when formatting arguments.”

0 Likes

#7

cmd cannot run commands such as mkdir, and it cannot pipe the in/output

0 Likes

#8

Shell constructs such as piping and redirection are not supported – see "shell_cmd" .

1 Like

#9

Probably cmd doesn’t invokes a shell, but shell_cmd does.


OK. I think your request is reasonable.

1 Like

#10

But in the exec.py in the bundled package, if the value is a array and it’s “cmd”, it simply just joins the strings, this could also be applied to shell_cmd

The strings are joined to show a status message only. Fundamentally running a shell command and running a process with arguments are different operations. Take for instance "cmd": ["rm", "foo bar.txt"] will delete the file names “foo bar.txt”. If you joined that and passed it to a shell it would delete 2 files “foo” and “bar.txt”. This is why "shell_cmd" only allows passing a string.

1 Like

#11

So sorry, my bad that I just noticed the log part

0 Likes