I have written a simple batch script which loops a directory and echoes some details about each file.When I view its results in the CMD terminal or output it to some file, I can view the results as expected.
The problem comes with PostgreSQL: when I try to import its results into a table, executing the following command:
copy schema.table(field) from program 'C:\\...\\my_bat.bat' with CSV header delimiter E'\t';
It imports 0 results, whereas if I run the same command pointing to a similar batch file in another directory, it works as expected.
What's going on? I am using windows.
Update: I have tried running the copy command calling program again on another batch script and this time, only a part of the string output is being imported.
The service user postgres needs sufficient permissions to run the program.
I remember that it was hard to change settings for that account on windows XP, I have not tried on more recent windows - service users are hidden by most GUI tools.
Related
I'm installing the Algolia extension for Firestore. Setup works just fine and it updates indices on add delete and update. But now I want to backfill it with existing data.
The following steps are provided in the setup guide but I have no clue on HOW to run that script. I've tried pasting it directly in node shell and powershell, adding it to a js or ps1 file and running that but I don't know what kind of script this is.
How do I run this script? (I have a service account json next to it)
It's bash...
It works when pasted directly in bash with spaces on each newline after the line terminator. Or as a .sh file from the commandline.
#!/bin/bash
LOCATION=europe-west3\
ALGOLIA_APP_ID=xxx\
ALGOLIA_API_KEY=xxx\
ALGOLIA_INDEX_NAME=organizations\
COLLECTION_PATH=organizations\
FIELDS=name,address,city\
GOOGLE_APPLICATION_CREDENTIALS=./xxx.json\
npx firestore-algolia-search
Trying to run an orientdb script from the command line using:
console.bat then the script name e.g. console.bat myscript.osql.
When I run the command I get an error
!Unrecognized command: '?select from TestClass' (TestClass isnt the real class but it will do).
If I run the commands manually on the console they work as I would expect.
I am on windows 10 creators edition, orientdb 2.2.30.
Assuming you're connected to your database and your script is in the same directory as console.bat (bin), you should execute LOAD SCRIPT myscript.osql to properly load it.
See LOAD SCRIPT from the docs.
I have 1000 images, and thanks to ImageMagick I can retrieve a lot of information regarding an image by writing "identify -verbose [PATH OF IMAGE]" in the cmd.
I installed ImageMagick with 'legacy on' , to access individual tools rather than the monolithic version of the library.
If I write "identify -verbose C:\\temp\\cbirCorel10k\\1.jpg" in the command prompt it works perfectly, outputting data I need.
My problem is when I insert this code into PROGRAM of PostgreSQL like so :
copy manyline(txt)
from program 'identify -verbose C:\\temp\\cbirCorel10k\\1.jpg'
It gives me this error, and please note that I do have permissions on the image and parent folders to be accessed:
ERROR: program "identify -verbose C:\temp\cbirCorel10k\1.jpg"
failed SQL state: 38000 Detail: child process exited with exit code
1
I want that the output from that command line, is inputted into the table 'manyline' under column 'txt'.
Please note that the following code works well, but I want to make use of the PROGRAM function.
copy manyline(txt)
from 'C:\\temp\\something.txt'
The postgresql server needs permissions to run that program and read that file. it usually runs under username postgres (unless they've changed that recently). this is a "service user" and can be hard to find in the windows GUI; especially on "home" editions of windows. I can't say for sure if granting NETWORK SERVICE access is enough.
easiest solution is to use the psql command-line interface and do
\copy manyline(txt) from program 'identify -verbose C:\\temp\\cbirCorel10k\\1.jpg'
\copy is a psql built-in which runs the command (opens the file etc) as the current user, instead of asking the server to run it. this also works well where the server is not local.
I have changed the shell key in windows registry to gain custom shell (Kiosk usage):
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon]
I set shell key to a batch file which runs two applications as below:
start "myFirstAppTitle" "myAppPath\myApp1.exe"
start "mySecondAppTitle" "myAppPath\myApp2.exe"
Each application runs but the second application which needs some files to be excuted throws an error which says could not find dependency files. whereas the dependency files are adjoining to the exe file and the mentioned app works fine, when starts from startup.
Meanwhile when i run the batch file manually it rusn fine.
I added the PATH command to the batch file but it did't work too.
Change the batch file to this:
set PATH=%PATH%;C:\MyAppPath
start "myFirstAppTitle" "myApp1.exe"
start "mySecondAppTitle" "myApp2.exe"
If you start executables without an absolute path, the path is relative to the current working directory. Also, when you specify an executable with a relative path, %PATH% is not searched for a matching subfolder with a matching executable.
Since the script worked when you manually started it, your working directory probably was C:\. However, when run at logon as a replacement shell, the working directory is most likely "%SystemRoot%\system32".
The problem solved strangely, i removed the title parameter of start command and it worked. In fact i used start command this fashion:
set PATH=%PATH%;C:\MyAppPath
start myapp.exe
start myapp2.exe
I have a startup task for my webrole that download some executable file from a blob and then proceed to the installation.
From a .cmd file, I start a power shell script that download the files, then I start the file from the .cmd.
The script works fine if I run it manually through RDP after the publishing is done.
But, when running as startup script, it sometimes (often) fail at different points.
The taskType is set to background.
Last time, the error was that the command PowerShell does not exists...
Also, I use powershell -command set-executionpolicy unrestricted before running my PS script, but I read here that other task may reset this setting and make mine fail.
Quite a mess.
So that makes me think that if I could wait for all other task to perform before starting mine, it would eliminate these kinds of problems
I suppose I could check if some process is running and wait for it to finish, but I have no clue wich process to check.
Or maybe there's another solution.
~edit~
I read here that the error about powershell not existing may be caused by the batch file being saved as UTF-8 in visual studio. I re-writed it from scratch in notepad++ and made sure it is save as ANSI. Then, same error. The full message is :
'PowerShell' is not recognized as an internal or external command,
operable program or batch file.
Again, the script run perfectly from command line in remote desktop.
It would be possible to set an environment variable at the end of the script that is required to finish, then in the script which is awaiting the dependencies, loop until the environment variable is set, then kick off its activities.
You could also run everything from a single powershell script and use the '-asjob' switch on your installer statement, use the 'wait-job' cmdlet to block until the task is complete then carry on. Powershell also offers a '?!' operator which ensures the last statement executed properly.
This might be caused by an encoding issue. As mentioned in this answer you should save your file in ASCII to ensure correct interpretation of your script.
From the linked answer:
Open your whatever.cmd file with your VS 2012 Ultimate. Click on File->Save whatever.cmd as -> on the dialog there is little arrow next to the [save] button. It will show up a menu that will have the option Save with Encoding.
Select it. Now choose "US-ASCII Codepage 20127" from the list of available encodings.