"public://" is not resolved correctly to the full path In my script, public:// resolves to http://./sites/default/files/test.txt

This is the code I used to get the actual value for public://: 

$path = file_create_url('public://test.txt');


$GLOBALS['base_url'] is also resolving to http://.

Any idea why the domain is missing from the public://?

Thanks
The reason there's no $base_url is because the script you're running isn't in a HTTP context; when Drupal bootstraps, unless you've specified a $base_url in settings.php, it retrieves this value from $_SERVER['HTTP_HOST'] which doesn't exist in the command line context.

To remedy this, you can set the $base_url in your settings.php or, if you're running Drush, use the --uri argument.

drush scr --uri="http://www.example.com" my_script.php