1

(On Windows 7 64 bit)... I am looking for a program, something similar to the default Windows Terminal, what I need it to do is:

Load text from a given URL, split the code in two variables and then trigger a simple Windows command based on these two variables.

Currently I am doing this with PHP ...

<?php 
$my_vars = file_get_contents('http://site.com/data.txt');
list($var1, $var2) = explode($my_vars);
exec("my command $var1 $var2");
?> 

This does the job fine but I don't like having PHP installed on Windows for something as simple as this. I am looking for a more compact file that maybe can be triggered from command prompt and doesn't have many additional files or dependencies, I need it to run on 2-3 computers too.

  • This looks horrendously unsafe. If you are getting a file from the internet it could contain anything. I wouldn't want to go around execing it. – Will Jul 15 '13 at 21:13
  • It's from my own domain, I know that dns hacks can get around that, but it gets plain text that I place in some quotes. More like command "$var1" "$var2" – adrianTNT Jul 15 '13 at 21:16
  • Hmm, you could get around quoting in much the same way that SQL injection works. Just so long as you are aware of the almost limitless security hole that this code appears to have. I would suggest parsing the results found on the server in some way before choosing which command to run. This could be as simple as if ($var1 == 'foo') .... else if ($var1 == 'bar') .. else /*fallback*/ . – Will Jul 15 '13 at 21:21
4

Looks like you want some form of general purpose scripting language. Windows batch scrips are the traditional way of doing simple tasks like this on Windows. In more modern versions this has been replaced with Powershell Scripts.

Seen as you want to get things from a URL you might want to use a more powerful language however such as Ruby or Python. Both are quite capable of accomplishing the task as simply as PHP does it in your example. The choice between the two is more a matter of style and familiarity rather than one of capability.

  • Yes, Python can probably do that too, but the "simplicity" level of keeping the Python files on the computer for this one simple task is similar to the PHP, and I'm already familiar with PHP, so I would end up keeping the PHP solution than using Python for this. – adrianTNT Jul 15 '13 at 21:25
  • 3
    If you want to script without having to install a language then Batch Scripting or Powershell is the way to go. – Will Jul 15 '13 at 21:29
  • Yes, I forgot to reply about your other suggestions (Powershell and batch scripts), I actually bumped into PowerShell a few times on last few days while looking for a solution. Looks like batch scripts cannot easily open URL so will look into PowerShell. Thank you. – adrianTNT Jul 15 '13 at 21:32
  • Yeah, batch is a bit outdated. I have no idea how you would download a file with it. – Will Jul 15 '13 at 21:33
1

Another way of doing things like this when Windows batch scripts are not powerful enough is using VBScript - not so nifty as Powershell, but IMHO easier to "grok". See here for an example routine for HTTP downloading, and here how to execute a command. VBScript is part of every Windows installation since ~2000. Powershell is only preinstalled for Win7 and later (which may suffer your needs).

  • Ok. The more I look into this, the simpler my initial PHP solution looks :) – adrianTNT Jul 15 '13 at 21:57
  • @adrianTNT: since you don't want to save the result into a file, I am pretty sure that VBScript example can be shortend to your needs. – Doc Brown Jul 15 '13 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.