How to call a bat file in new window - winapi

I have a little bat file which calls other bat files:
cd C:\Users\Ofis\heroku\1134 && call up.bat
cd C:\Users\Ofis\heroku\5095 && call up.bat
cd C:\Users\Ofis\heroku\9469 && call up.bat
It works good, but I want it call .bat files in new windows so it will be synchronous and faster. How can I do this?

You can make use of start :D
cd C:\Users\Ofis\heroku\1134 && start up.bat
cd C:\Users\Ofis\heroku\5095 && start up.bat
cd C:\Users\Ofis\heroku\9469 && start up.bat

Related

Bash run two commands both dependent on the first

I'm sure this has been asked but my search has been fruitless.
I want to run 3 bash commands in order with both the second and third only running if the first succeeded.
Example:
## Setup
mkdir so_test_tmp && cd so_test_tmp
echo "This is something" > something
cd ..
## Example commands
cd so_test_tmp ??? cat nothing ??? cd .. # 0.
cd so_test_tmp ??? cat something ??? cd .. # 1.
cd does_not_exist ??? cat nothing ??? cd .. # 2.
These three commands should always end in PWD. In 0. the first cd is run, then the last. In 1. all three commands successfully run. In 2. the first command fails so the second and third are not run.
What about?
pushd .; cmd1 && cmd2 && ... cmdn; popd
pushd . saves your current dir.
Then you execute your commands; you use && so that, if one fails, the others are not executed.
popd goes back to your initial dir.
EDIT: regarding your comment below, yes, this pushd .; popd construct is quite silly; it lets you forget about how the execution of each set of commands went.
pushd .; cd so_test_tmp && cat nothing; popd; # 0.
pushd .; cd so_test_tmp && cat something; popd; # 1.
pushd .; cd does_not_exist && cat nothing; popd; # 2.
You finish at your original dir after running the three sets of commands.
Within each set of commands, whenever a command fails, it shortcuts the execution of the others behind (see they are separated by &&).
If you need to know if each set of commands succeeded or not, you can always test the result of the execution (and go to your initial dir and save it again before running the following set of commands):
pushd .;
cd so_test_tmp && cat nothing && cd .. ; # 0.
test $? -eq 0 || (popd; pushd .) ;
cd so_test_tmp && cat something && cd ..; # 1.
test $? -eq 0 || (popd; pushd .) ;
cd does_not_exist && cat nothing && cd ..; # 2.
test $? -eq 0 || (popd; pushd .) ;
Specifically for cd somewhere && somecommand && cd ..
The cd .. is only necessary because you're doing cd so_test_tmp inside your parent shell, as opposed to the subshell that's fork()ed off to then be replaced with a copy of /bin/cat.
By creating an explicit subshell with ( ... ), you can scope the cd to its contents. By using exec for the last command in the subshell, you can consume it, balancing out the performance overhead of that subshell's creation.
(cd so_test_tmp && exec cat nothing) # 0.
(cd so_test_tmp && exec cat something) # 1.
(cd does_not_exist && exec cat nothing) # 2.
Note that this applies only when the command you're running in a subdirectory doesn't change the state of the shell that started it (like setting a variable). If you need to set a variable, you might instead want something like output=$(cd /to/directory && exec some_command).
Answering the more general question
Use && to connect the first command to a group with the second and third commands, and use ; to combine those 2nd and 3rd commands, if your goal is to ensure that both 2nd and 3rd run if-and-only-if the 1st succeeds.
cd so_test_tmp && { cat nothing; cd ..; } # 0.
cd so_test_tmp && { cat something; cd ..; } # 1.
cd does_not_exist && { cat nothing; cd ..; } # 2.
Setup:
$ cd /tmp
$ mkdir so_test_tmp
$ echo "This is something" > so_test_tmp/something
Wrapping an if/then/fi around OPs current examples:
$ if cd so_test_tmp; then cat nothing; cd ..; fi ; pwd
cat: nothing: No such file or directory
/tmp
$ if cd so_test_tmp; then cat something; cd ..; fi ; pwd
This is something
/tmp
$ if cd does_not_exist; then cat something; cd ..; fi ; pwd
-bash: cd: does_not_exist: No such file or directory
/tmp

How to change drive in Makefile?

The target (rule) in my Makefile has a series of commands. First few commands should be executed from D:\ drive. After this, I should change my directory to C:\ so that I can execute a file in C:\ drive. But, I am not able to change drive. I tried the following ways:
C: (it works in cmd but not in Makefile)
cd /d C: (not working)
cd C: (not working)
Please let me know how to change drive from within a make rule.
This can be achieved by using either ; or && \
cd d:\folder1 && \
dir && \
echo "all files in d:\folder1 are listed"
cd c:\folder2 && \
dir && \
echo "all files in c:\folder2 are listed"
is equivalent to
cd d:\folder1; dir; echo "all files in d:\folder1 are listed"
cd c:\folder2; dir; echo "all files in c:\folder2 are listed"

Sun Grid Engine - Submitting job from command line

I'd like to submit a job to the Sun Grid Engine using a single command line argument, rather than using a shell script. Can it be done?
Example:
I want to do this, and submit to the batch queue:
mkdir empty_directory && cd "empty_directory" && touch "empty_file.txt"
Rather than doing this:
dir_script.sh:
#!/bin/bash
mkdir empty_directory
cd empty_directory
touch empty_file.txt
Then:
qsub dir_script.sh
I do this all the time, using pipe (|):
echo "mkdir empty_directory && cd empty_directory && touch empty_file.txt" | qsub [options]

Create multiple files in a directory without change current directory

I'm using command below in my mac machine:
mkdir views && touch views/layout.erb views/home.erb views/about.erb views/contact.erb
It's working as expected. But i'm looking for something, so that i don't have to use directory name(views) to create/touch each file.
You can use bash expansion to make this more concise:
mkdir views && touch views/{layout,home,contact}.erb
You can do something like:
mkdir views && touch views/{layout,home,about,contact}.erb
Or you can change the directory in a sub-shell, so your current shell's working directory is unchanged:
mkdir views && (cd views && touch layout.erb home.erb about.erb contact.erb)
Another option is to use a loop:
mkdir views && for f in layout home about contact ; do touch views/${f}.erb ; done
mkdir views && pushd views && touch layout.erb home.erb about.erb contact.erb && popd
Or:
mkdir views && (cd views && touch layout.erb home.erb about.erb contact.erb)

Update multiple heroku apps by batch script

i have nearly 30~ heroku apps i want to update them by just 1 hit. i just made a simple batch but it doesn't focus to 2nd line after the first line is ok
cd C:\Users\Ofis\heroku\app1 && up.bat
cd C:\Users\Ofis\heroku\app2 && up.bat
cd C:\Users\Ofis\heroku\app3 && up.bat
cd C:\Users\Ofis\heroku\app4 && up.bat
cd C:\Users\Ofis\heroku\app5 && up.bat
cd C:\Users\Ofis\heroku\app6 && up.bat
up.bat =
git add .
git commit -m "update"
git push heroku master
You need to use call if you want to invoke a sub-script and return to the main script after it completes.
cd C:\Users\Ofis\heroku\app1 && call up.bat
cd C:\Users\Ofis\heroku\app2 && call up.bat

Resources