Home / Microsoft / Microsoft DOS / "Set" in batch file
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: "Set" in batch file  (Read 1864 times)
graceguo
Guest
« on: January 04, 2006, 02:46:06 PM »

I need to set two environment variables: test_input and test_output

set test_input=..\..\testfiles\test0.txt
set test_output=..\..\temptest\out.%test_input:..\..\testfiles\=%

This works very well under command prompt and in a batch file only with these two lines. But when I
put it into one of my batch file, like

if %test_exefile%==repack (
     set test_input=%1                            :: this line works fine and %1 will set to .\..\testfiles\test0.txt
     set test_output="..\..\temptest\out.%test_input:..\..\testfiles\=%
     ...
)

The first set line works fine. But the second variable (test_output) will set to ..\..\temptest\out...\..\testfiles\=

I also tried to replace the second set with the
set test_output="..\..\temptest\out.%test_input:~16%"
Use this, I will set test_output="..\..\temptest\out.~16", but it works under command prompt.

Anyone can give any kind of helpful thoughts? Thanks in advance!

 :'(

IP logged
Roofvogel
Guest
« Reply #1 on: January 04, 2006, 02:56:41 PM »

I do not know a lot about batch files, but I think temptest is too long a directory name.
IP logged
graceguo
Guest
« Reply #2 on: January 04, 2006, 03:06:16 PM »

I thought that was the case. So I tried to put only those two lines into a batch file. It works.
There might be some other reasons I don't know
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #3 on: January 04, 2006, 06:55:21 PM »

My thoughts are that the punctuation is in error:

Code: [Select]
f %test_exefile%==repack (
     set test_input=%1                            
     set test_output="..\..\temptest\out.%test_input%:..\..\testfiles\=%
     )

I'm not sure you really want the leading quote or the trailing % on test_output. But hey, it's your code. For what it's worth, why the set test_input=%1? Why not just use %1 directly in the set test_output?

Just my 2 cents. 8-)

« Last Edit: January 04, 2006, 06:56:35 PM by Sidewinder » IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
graceguo
Guest
« Reply #4 on: January 05, 2006, 10:50:52 AM »

Hi, expert

It's possible to use %1 to replace test_input.

If %1 is ..\..\testfiles\test0.txt and I want to set test_output is ..\..\temptest\out.test0.txt

Use environment variables, we can set test_output=out.%test_input:..\..\testfiles=%. This will remove ..\..\testfiles in %test_input%.

But if I use %1, I don't know how can I do it? Expecting your idear?
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #5 on: January 05, 2006, 04:10:34 PM »

Based on your code:
Code: [Select]
test_input=..\..\testfiles\test0.txt
test_output="..\..\temptest\out.%test_input:..\..\testfiles\=%

There is nothing to replace. You are trying to resolve a variable named %test_input:..\..\testfiles\=% which doesn't exist.

If you move the %, something like this: %test_input%:..\..\testfiles\=,  a replacement will be made although I'm not sure that's the result you want. Environment variables are strings resolved to their actual value and are only recognized by the surrounding %. The interpreter will not see %test_input as a replacable parameter.

What result are you looking for? 8-)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / "Set" in batch file « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.081 seconds with 20 queries.