Run cmd command with CD

Asked

Viewed 280 times

0

I’m looking to execute a specific command of composer update by cmd. However, I always need to access my api folder with cd to execute such. Example:

C:\Users\Luiz>cd api
C:\Users\Luiz\api>composer update

Is there a way to do this in one command? Type:

C:\Users\Luiz>cd api composer update

3 answers

2


you can use the & to execute single-line commands ex:

cd Links & dir

you can also use the && in this case it only executes the second command if the first is executed without errors:

cd Links && dir

try using your commands and be happy:

cd api & composer update

1

Whereas the path to the api has already been set in the variable %path%, you have already tried only to run call composer update? Look at that answer Running "Composer update" Within a Windows . bat file

Use the command cd == check directory, using the flag /d, makes go to the drive, useful option when using commands between folders and different drives.

Your command can be on a line using operators:

• Observations on operators: &, |, && e ||

execute & execute & execute

execute | recebe _saída_do_comando_anterior

execute | recebe _saída_do_comando_anterior & execute

executou_sem_erro && então_execute_também

executou_com_erro || execute_também_porque_deu_erro

executou_com_erro || executou_com_erro || executou_com_erro 

executou_sem_erro && executou_sem_erro && executou_sem_erro

executou_sem_erro && então_execute || execute_esse_no_primeiro_deu_erro 

rem :: entre na pasta/check directory
cd /d "C:\Users\Luiz\api"
rem :: daí execute o update do compuser ::
composer update

rem :: ----------

rem :: para fazer em uma linha ::
cd /d "c:\Users\Luiz\api" && composer update 

rem :: usando variável %userprofile% do ambiente ::
rem :: usando operador && (execute (se executou sem erro) && também execute)
cd "%userprofile%\api" && composer update 

For most Apis, sending commands for execution is in this syntax:

cmd /c cd /d "C:\Users\Luiz\api" && composer update

Already in compuser is different, in it you use script by predefined event, or something like.

But I think it would be better to take a look at the documentation that addresses the ways to add scripts/commands on the computer:

One answer treating the use of script in the computer

Like make a Calling Composer

Answer how to run a cmd/bat to update the Composer

5 tricks of the composition

0

set composerup=cd api ^& composer update

execute the command:

%composerup%

Browser other questions tagged

You are not signed in. Login or sign up in order to post.