Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › help with turning lines of text into variables
New Posts  All Forums:Forum Nav:

help with turning lines of text into variables

post #1 of 4
Thread Starter 
Hello again,

Is it possible to take a list of words from one text file and use each one as a variable in a batch file??

Right now I'm doing something like this...


Echo %1 %2 %3

so in the command prompt I have to type each variable in after the batch file name (C:\\>test.bat var1 var2 var3 etc.)

So instead of typing the variables, the text file would provide them for me.

Am I even making sense?
    
CPUMotherboardGraphicsRAM
AMD 64 3500+ Asus A8N SLI Delux 128 MB 1024 MB 
Hard DriveOSMonitorKeyboard
Almost a TB XP Pro Some cheap Flat Panel Wireless Microsoft 
PowerCaseMouseMouse Pad
600 watt embarassing Wireless Microsoft Laser Stooges Baby!! 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD 64 3500+ Asus A8N SLI Delux 128 MB 1024 MB 
Hard DriveOSMonitorKeyboard
Almost a TB XP Pro Some cheap Flat Panel Wireless Microsoft 
PowerCaseMouseMouse Pad
600 watt embarassing Wireless Microsoft Laser Stooges Baby!! 
  hide details  
Reply
post #2 of 4
Thread Starter 
I got it!
Put the default arguments into a file with the same name as the batch and extension arg
Quote:
@echo off
if "%~1" EQU "" if exist %~dpn0.arg (
set /P StdArg=<%~dpn0.arg
call "%~f0" %StdArg%
exit /B
)
:: batch code here
    
CPUMotherboardGraphicsRAM
AMD 64 3500+ Asus A8N SLI Delux 128 MB 1024 MB 
Hard DriveOSMonitorKeyboard
Almost a TB XP Pro Some cheap Flat Panel Wireless Microsoft 
PowerCaseMouseMouse Pad
600 watt embarassing Wireless Microsoft Laser Stooges Baby!! 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD 64 3500+ Asus A8N SLI Delux 128 MB 1024 MB 
Hard DriveOSMonitorKeyboard
Almost a TB XP Pro Some cheap Flat Panel Wireless Microsoft 
PowerCaseMouseMouse Pad
600 watt embarassing Wireless Microsoft Laser Stooges Baby!! 
  hide details  
Reply
post #3 of 4
Very helpful. Is this possible in other languages? Something where you could could have a text file containing:

int x = 5;
double y = 3;

And have a program read those lines as if they were in the code themselves? I would imagine not, since the code gets compiled and built before running, but I guess I can hope.
RAID0R
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 4.0GHz MSI P55-GD80 GTX 470 | 8800GT PhysX 2x2GB G.Skill Ripjaws 
Hard DriveOptical DriveCoolingOS
60GB Agility 2|1TB RAID0|1.5TB Pioneer DVR-217D XSPC Raystorm | XSPC RX240 Windows 7 Professional x64 
MonitorKeyboardPowerCase
27" Dell 2709W | 17" Samsung Logitech G15 Corsair HX850 Corsair 650D 
Mouse
Microsoft IntelliMouse 
  hide details  
Reply
RAID0R
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 4.0GHz MSI P55-GD80 GTX 470 | 8800GT PhysX 2x2GB G.Skill Ripjaws 
Hard DriveOptical DriveCoolingOS
60GB Agility 2|1TB RAID0|1.5TB Pioneer DVR-217D XSPC Raystorm | XSPC RX240 Windows 7 Professional x64 
MonitorKeyboardPowerCase
27" Dell 2709W | 17" Samsung Logitech G15 Corsair HX850 Corsair 650D 
Mouse
Microsoft IntelliMouse 
  hide details  
Reply
post #4 of 4
I know you can do it in other languages like perl and ruby, where you can have it go through a whole file of number or whatever, and it'll use them like args.

file would be something simple like:
5
10
12.2
Some text
4
56
etc...

Something similar could be done in java using args[#]. If its a mix of primitive types though it'd become harder b/c everything would have to be a string and if you need something to act like a number then you'd have to parse it. Where in something like perl it converts between string and numbers depending on how its being used, so its a much easier process in a high level language like that.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › help with turning lines of text into variables