Batch file appears not to run and shuts down immediately [closed] - windows

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to run a batch file with the following code:
set dirA=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\In
set dirE=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\OutPut
set dirC=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\Processed
The batch file does not run and shuts down immediately and I cannot figure out what is wrong.

Couple of things you need to understand. When we set variables, we typically enclose them in double quotes in case there are whitespace, which after the whitespace, the next field is seen by cmd as a new command and you will get some errors you would not want, such as the infamous "Is not recognised as an internal command on batch file` error, so we would therefore rather do this:
set "dirA=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\In"
set "dirE=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\OutPut"
set "dirC=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\Processed"
The code then does exactly what you told it to do and that is to simply set variables %dirA% %dirE% and %dirC% with the respected values.
Now to see a result, you need to do something with those variables, perhaps we echo them?
#echo off
set "dirA=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\In"
set "dirE=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\OutPut"
set "dirC=C:\SE_BulkUnzipTarGzipFiles\WinRarSamples\Processed"
echo %dirA%
echo %dirE%
echo %dirC%
pause

Your script runs, but it finishes almost immediately.
If you add a pause command at the end, the window will stay open until you press a key.

Related

cd %C^ in command promt? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I khow im a bit off topic because posting here,but this is prety weird.
i were just testing cmd,when i enter this command:cd %C^
it show :
"more?"
"more?"
"The system cannot find the path specified."
this is weird because it is showing "more?",so i have tried researching on the internet,but found thin air.
screenshot:
https://imgur.com/a/kiZIECy
is this normal?
"More?" means the cmd is asking you to continue your command.
"^" is an escape character when you use this character the cmd does not just runs whole command and shows you the result but instead it breaks the command in parts that it will run as you press enter key when it says "more?" it asks you if you want to run the next part of the command and at the end it reaches at the same result as writing a command as "cd %C".
if you have used linux you can see this type of interpretation when you open a large file using cat(a file reading function in bash that prints out the text file as you press enter).

How to perform arithmetic on automator variables [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'd like to be able to divide the value of a variable in Automator by 2, before being passed to the next step. I imagine it can be done with 'run applescript' but can't figure out how.
Sure. If you have a variable with a number in it, you can:
Get Value of Variable
Run AppleScript
with the AppleScript something like:
on run {input, parameters}
set halfInput to input / 2
return halfInput
end run
I’ve attached a screenshot of this, so you can see how it works.
Note that depending on where the variable is set, it might be a list, in which case you’ll need to get the appropriate item from the list. For example, passing the result of a shell script to a variable will mean that the value is in a list, and the AppleScript will need to get the “first item of input” in order to treat that value as a number. Here’s an example:

run vbscript mhta [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to run vbscript from mhta
mshta "vbscript:window.close(msgbox("test"))"
WScript or CScript script hosts are not able to run a script if it is not stored in a file. But you can use mshta and the vbscript: protocol to run simple commands.
Anyway, for this case, it is easier to use
msg console "test"
edited to adapt to comments
i've being testing. vbscript parser in the mshta url has to face a lot of limitations. And problems with spaces, concatenation of commands with :, problems with procedure calling as a function but you can not use call keyword as a space is required, ....
The only stable, "easy" way of doing it is to prepare the vbscript to execute as a string, with no spaces inside it, and use the execute method to run it
mshta "vbscript:window.close(execute("msgbox"&chr(32)&"""test"":msgbox"&chr(32)&"""this"&chr(32)&"should"&chr(32)&"work"""))"
mshta "vbscript:window.close(execute("server=CreateObject(""WScript.Shell"").RegRead(""HKEY_CURRENT_USER\Volatile"&chr(32)&"Environment\LOGONSERVER""):For"&chr(32)&"i=1"&chr(32)&"to"&chr(32)&"3:msgbox"&chr(32)&"i"&chr(38)&"server:next"))"

Use substring against a file with varied length strings [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a file which contains values like
10AB1CD1278A
10AB5CD12578HJI
Using the below
set var=10AB2CDEFG12345
set "var=%var:~2,4%"
echo %var%
Expected answer "AB1C".Which is 4 characters after the digit 10.
Since the values within the file are of varied length the above doesnt work for all the values contained.
OK, after looking at you comments I think we can understand that you want to create a batch file which goes through every line in a text file and present to you the desired series of four letters. If so, very easy. Run this in the same directory, with the file saved as input.txt
Code :
setlocal enabledelayedexpansion
for /f %%a in (input.txt) do (
set var=%%a
set "var=!var:~2,4!"
echo !var!
)
Note: I kept the commands as they were incase you intended to do something else with it.
Hope this helped, Mona

Why the backslash in bash? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I exported a variable in ~/.bashrc as follows (followed by source ~/.bashrc)
export w=/home/user/workspace/
When I'm on commandline I try to access sub-directories of $w in following way
user$ vi $w/
After this when I hit the tab key, a mysterious backslash appears
user$ vi \$w/
It disables further tab-completion. Why? May not be vi specific as it occurs even with ls.
Bash version 4.2.24(1)-release (i686-pc-linux-gnu)
Running Ubuntu 11.04
Edit
Workaround: Hit Esc+Ctrl+E before hitting tab.
Bash is a little smart, but not that smart. It's not going to be able to expand out your variable, then tab complete to whatever dir that evaluates to. So it's not the backslash "disabling" tab completion, it's the fact that bash can't find any completion suggestions to make.
Given that completion isn't going to help you if you actually do have environment variables in your path, the only way completion could help you at all is if you meant to type a literal dollar sign. I think bash is just being overzealous in trying to complete to something.
Still, I'd call it a bug, since in your case it not only fails to complete, but also changes the meaning of what you've typed.

Resources