python is not recognized as an internal or external command while running batch file - python-2.7

I am set environmental variable for python and I am able run python if I not take user input in batch file. But If I take user input I am not able to run python scripts in batch file.
#echo off
set /p Path="Enter Folder path in which all the timestamp files are stored: "
echo %path%
:: this is to read ip address from report folder to ipaddress.txt
dir %Path% /b /a-d > ipaddress.txt
echo %cd%
python trial.py

Choose a variablename other than path.
path is a reservd name that contains a list of the directories to search for an executable - like python.exe

Related

error: the path "nginx-deployment.yaml" does not exist when I use kubectl apply -f nginx-deployment.yaml

I use kubectl apply -f nginx-deployment.yaml enter image description here
Try giving the full path like C:\YAML\nginx-service.yaml
If the yaml file will be in .txt format then convert it into filename.yaml("in filename, name it as you like").Copy the content of the yaml text document("which creates the error") and paste the content in notepad++ and save the file as filename.yaml.
Open the cmd, then command
"docker login"
after that, change the directory to yaml file located directory
"cd directory path"
here directory path is(C:\Users\ELCOT\job-portal\job portal\filename.yaml).Don't consider this path,it's an example.Type your system directory path .
After changing the directory,command
"kubectl create -f Filenae.yaml"
it will load for few minutes, then it shows
"Filename.apps/flask-node-deployment created" .
The above mentioned instructions will works on windows platform ,not in MAC.

How can I check if either or file exists in IF Exist?

How can I check if either or file exists in a If Exist statement?
Such as
If exist "C:/Windows/" OR "C:/Windows2" (
Do something
) else (
Something else
)
How would I do this? I just want either or to exist and to do something.
Simple example 1:
#echo off
if not exist "%SystemRoot%\" if not exist "C:\Windows2" goto MissingFolderFile
echo Found either the directory %SystemRoot% or the file/folder C:\Windows2.
rem Insert here more commands to run on either the folder C:\Windows
rem or the file/folder (=any file system entry) C:\Windows2 existing.
goto EndDemo
:MissingFolderFile
echo There is neither the directory %SystemRoot% nor the file/folder C:\Windows2.
rem Insert here more commands to run on neither folder C:\Windows
rem nor file/folder C:\Windows2 existing.
:EndDemo
pause
The Windows command processor is designed for processing one command line after the other which is the meaning of the word batch. The command GOTO is the preferred command to use in a batch file to continue batch processing not on next command line, but another one depending on an IF condition, i.e. change processing from one stack (other word for batch) of command lines to another group of command lines.
Simple example 2:
#echo off
if exist "%SystemRoot%\" goto FolderExists
if exist "C:\Windows2" goto FS_EntryExists
echo There is neither the directory %SystemRoot%\ nor C:\Windows2.
rem Insert here more commands to run on neither folder C:\Windows
rem nor file/folder/reparse point C:\Windows2 existing.
goto EndDemo
:FS_EntryExists
echo The file system entry (file or folder) C:\Windows2 exists.
rem Insert here more commands to run on C:\Windows2 existing.
goto EndDemo
:FolderExists
echo The folder %SystemRoot% exists.
rem Insert here more commands to run on folder C:\Windows existing.
:EndDemo
pause
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
goto /?
if /?
rem /?
NOTE:
The directory separator on Windows is \ and not / as on Linux or Mac. The Windows file management automatically replaces usually all / by \ before passing a file/folder argument string without or with a wildcard pattern to the file system as explained by Microsoft in the documentation about Naming Files, Paths, and Namespaces. But the usage of / instead of \ in file/folder argument strings can result nevertheless in unexpected behavior.
Example for unexpected behavior because of using / on running following command line directly in a command prompt window:
for %I in ("%SystemDrive%/Windows/*.exe") do #if exist "%I" (echo Existing file: "%I") else echo File not found: "%I"
This command line outputs a list of executable file names found by FOR in the Windows directory which do not exist for command IF just because of usage of / resulting in getting assigned to the loop variable the found file names without path. So this command line works only if the current directory on system drive is by chance the Windows directory.
The same command line with usage of \ as directory separator:
for %I in ("%SystemDrive%\Windows\*.exe") do #if exist "%I" (echo Existing file: "%I") else echo File not found: "%I"
This command line outputs each file name of the executables in Windows directory as existing file with full path.
Another example:
There is in root directory of current drive a directory Downloads and the current directory on this drive is Temp, for example D:\Downloads is the wanted current directory and D:\Temp is the current directory.
The used command is:
cd /Downloads
The result is the error message:
The system cannot find the path specified.
The command with correct directory separator usage:
cd \Downloads
This command works on D:\Temp being the current directory and D:\Downloads existing.
CD interprets on incorrect /Downloads the string /D at beginning of the directory path as option /D to change also the drive and searches for that reason for ownloads in current directory instead of Downloads in root directory of current drive. This wrong interpretation by CD is avoided by using the correct directory argument string \Downloads.
SUMMARY: \ is the directory separator and / is for command options.

How to split text file elements using a windows batch file?

I have a text file RECORDS containing a list of addresses to series of record files from physionet website:
Person_01/rec_1
Person_01/rec_2
.
.
.
Person_90/rec_1
Person_90/rec_2
I need to execute a command as below to each line of text file as below:
wfdb2mat -r rec_1 -f 0 -t 20 > rec_1m.info
Here, wfdb2mat is the command known to windows to convert .dat data structure in windows to .mat structure known to MATLAB. Output report of this command execution is stored as .info in the same directory as RECORDS line.
I have written a batch file (convert.bat) as:
#echo off
for /f %%a in (RECORDS) do (wfdb2mat -r %%~a -f 0 -t 20 > %%~am.info)
to convert all files listed in RECORDS.
But unfortunately, there are two other files naming .mat and .hea which are store in the same directory as convert.batch and named rec_Xm.mat and rec_Xm.hea, where X is the record number listed in RECORDS.
Thus, I need to add an extra command in the for loop to move those files to their place in the folder named in RECORDS.
My batch file is so changed to:
#echo off
for /f %%a in (RECORDS) do (wfdb2mat -r %%~a -f 0 -t 20 > %%~am.info & move rec_*.* %%~a)
The problem is that %%~a contains folder name and file name together, like Person1/rec_1 and I just need the folder name to move those files to.
How can I split these strings in order that I can extract folder name in each loop iteration?
Based on my comment and my assumption of what your command is supposed to do
#Echo Off
For /F "Tokens=1-2 Delims=/" %%A In (RECORDS) Do (
wfdb2mat -r %%A/%%B -f 0 -t 20 >%%A/%%Bm.info
Move /Y %%B.* %%A)

explorer command not working in batch file

i have a batch file that opens an item in a list of paths but the explorer command is not working (final is a list of paths )
can anyone tellme why this command isnt working
its sending the message:'explorer' is not recognized as an internal or external command,operable program or batch file.
setlocal enabledelayedexpansion
set path=c:\users\user1\desktop
set numz=0
set /p go=
for %%k in (%final%) do (
set /a "numz=!numz!+1"
if [!numz!]==[%go%] (explorer %%k)
)
you changed the %path% variable. Don't do that (use another variable name). Windows uses the %path% variable to know where to find it's executables. Because you deleted that info, Windows is not able to find explorer.exe any more - hence the error message.
Gladly, this concerns only the current cmd session (and it's daughter-processes). Change the variable name, close the cmd window, open a new one and it should work fine.

Windows move command not moving the matching file to destination folder using bat

I created a windows bat file which will create a directory and then create subdirectories finally it need to move the matching file to the destination folder but it is not moving showing error "A duplicate file name exists, or the file cannot be found" but I have the matching string in the folder. Please help on this
my batch script shows below
set AUTOMATEDDIR=C:/test/2122/Inter/Test/WEB
CD %AUTOMATEDDIR%\..\Reports\Deliverable
FOR %%d IN (AgentCreate) DO (
MKDIR "%%d"
FOR %%e IN (Requests Responses) DO (
echo inside
MKDIR "%%d\%%e"
MOVE "Unidentified\%%e\*%%d*" "%%d\%%e"
)
)
when I execute the above script it shows below error
C:\test\2122\Inter\Test\Reports\Deliverable>(
MKDIR "AgentCreate"
FOR %e IN (Requests Responses) DO (
echo inside
MKDIR "AgentCreate\%e"
MOVE "Unidentified\%e\*AgentCreate*" "AgentCreate\%e"
)
)
C:\test\2122\Inter\Test\Reports\Deliverable>(
echo inside
MKDIR "AgentCreate\Requests"
MOVE "Unidentified\Requests\*AgentCreate*" "AgentCreate\Requests"
)
inside
A duplicate file name exists, or the file
cannot be found.
C:\test\2122\Inter\Test\Reports\Deliverable>(
echo inside
MKDIR "AgentCreate\Responses"
MOVE "Unidentified\Responses\*AgentCreate*" "AgentCreate\Responses"
)
inside
A duplicate file name exists, or the file
cannot be found.
My folder Requests contains folder "Res_20121203_Test_1" as below
C:\test\2122\Inter\Test\Reports\Deliverable\Unidentified\Requests\Res_20121203_Test_1
Res_20121203_Test_1 folder contains files like below
-20121203B001601-292XtOHAAgentCreate601
-20121203B002603-292XtOHAAgentCreate603
The above files matching "AgentCreate" need to move "AgentCreate\Requests" folder also matching files to "AgentCreate\Responses"
Please help on this why it is not moving.
FOR %%d IN (AgentCreate) DO (
MKDIR "%%d" 2>nul
FOR %%e IN (Requests Responses) DO (
echo inside
MKDIR "%%d\%%e" 2>nul
FOR /f "delims=" %%t IN ('dir /s /b /a-d "Unidentified\%%e\*%%d*" 2^>nul') do MOVE "%%t" "%%d\%%e" >nul
)
)
I misread the requirement. This worked for me.
The 2>nul suppresses error messages. >nul suppresses "moved" reports and 2^>nul suppresses 'file not found' output of the dir. The caret is necessary to tell cmd that the redirection is part of the command to be executed, not part of the for.
Essetially, scan the trget directory for matching files /s in subdirectories /b in basic form (filename only) /a-d and no directorynames.
You may want to try echo move to verify operation.
Please note that \ is a directory-separator and / is a switch in winbatch. Some commands accept / as directory separators, but not all.