I want to be able to make a batchfile that will loop through every file in a directory and import it inside SQlite3. The problem I have is that SQlite3 does not accept multiple commands from command prompt/batch, only 1 command.
What I have tried is :
for %%f in (./tmp/*.csv) do (
echo %%f
sqlite3 database.db ".separator '|'" ".import './tmp/%%f' Dirs"
)
And I get a too many options error, as it is only expecting a single command, while I need more than 1.
I also cannot write a second text file to be called by sqlite3 as the file being imported will change for every iteration.
Help would be appreciated.
You can use the option -separator to set the separator (whose default already is |).
If you'd really need to execute multiple commands, you could write them to a file and .read that, or echo all of them and pipe them into sqlite3.
Related
I have a text file with lots of commands in it and I want to sent those commands to a software called thermocal. It is a console application. I found the command below, but it doesn't work for me.
Do I need to put this .exe file in the same folder of the batch file to make it work or any thing else?
type somefile.txt | Thermocal.exe
Batch scripts can be considered as a collection of lines you could also type in a command line prompt one after another. With respect to this it might be helpful for you, to play with cmd in order to get a feeling for what is happening.
About starting thermocal: Assuming thermocal is not part of PATH then the batch file either needs to change the current directory to the one with termocal.exe. Alternatively you might be able to call thermocal.exe with adding a path like C:\ProgramFiles\Thermocal\thermocal.exe . Play with cmd to find out, what works and what doesn't
When you are able to start thermocal from the command line prompt window, you can start experimenting with the call. You will probably end of with something like this in your command line window:
C:\ProgramFiles\Thermocal> thermocal argument1 argument 2
If this works, you can start with batch programming :)
Assuming your arguments are stored in somefile.txt like this:
argument1 argument 2
TYPE does nothing more than printing a file:
TYPE somefile.txt
Now you need to use the result of the output as command line arguments:
for /f %%i in ('type somefile.txt') do (thermocal.exe %%i)
I am trying to execute a shell command or batch file in LiveCode, however, for reasons unknown, it is not working. I would like to use another intermediate program to execute the batch file that records the output to a text file and then read that output with LiveCode as a workaround. What is a simple way to create an executable that can process a batch file?
There is not really any relevant code to share other than
put "test.bat" into tCommand
put shell (tCommand) into fld "output"
The following script works in LiveCode 6.7.6:
set the hideConsoleWindows to true
put shell("C:\test.bat")
My bat file contains
#echo off
echo 'test'
pause
and the value returned by shell() is
'test'
Press any key to continue . . .
The last character of the value returned is a linefeed.
Perhaps you should try to reproduce this simple test.
I have a batch file that first creates another batch file containing a ClearCase cleartool command and second, runs it:
ECHO cleartool lsactivity -long "%ACTIVITY%"^>"%OUTPUTFILE%">FILETORUN.bat
CALL FILETORUN.bat
When running the batch, FILETORUN.bat is generated with the correct format, but the CALL to it is completely ignored.
If I ECHO output after the CALL to a log file, I can see that the script just skips over it.
What could it be?
I have tried removing CALL but it makes no difference.
EDIT: SOLUTION
Thank you all for the input. I found the problem. Before the write to batch and batch call in the script there was a command that read information into a variable from a file:
SET /p FILETODELETE=<rmname_%CLEARCASE_USER%.tmp
It reads only the first line. For some reason this created a conflict with temporary batch file, and I have no idea why. I used a different solution for reading the first line from a file and the conflict doesn't happen anymore:
(set FILETODELETE=)
for /f "delims=" %%q in (rmname_%CLEARCASE_USER%.tmp) do if not defined FILETODELETE set FILETODELETE=%%q
If anyone can shed some light it would be great!
SET /P waits for user input, so it actually will finish the command with what you are trying to execute after that and consume the input buffer, which might produce different results on each machine.
See set command reference for more details
I need to create a batch file which will run a program (which has been created in C#.Net) and also take a path of a text file as an input.
Not quite sure, how to achieve this.
So far, I have the below command working,
C:\>Folder Path to executable>xxxx.exe -console
-console is my predefined command argument to run this program in console mode.
The part until running the program from the console, with -console, works perfectly fine with a hard coded file path. However, I want to give the functionality to the user to give the file path as they want and create a batch file for the same command. Everytime user can update the batch file with new text file path and simply run it.
Thanks,
Are you just wanting to use the -console parameter? Are there any other parameters you wanted to pass in?
If wanting just what you have in your snippet, Save the following into a batch file. (e.g. StartMyProgram.bat)
start "C:\Folder path to executable\xxxx.exe" -console
See start /? for help and more options.
You need to add %~1 to your script: C:\Path\to\executable\xxxx.exe -console %~1
Now you can call it like this: StartMyApp.cmd C:\Docs\readme.txt
%~1 contains the full path of the text-file. You could also ensure that only text-files are passed to your application:
if "%~x1"==".txt" (
C:\Path\to\executable\xxxx.exe -console %~1
) else (
echo Not a textfile! & pause
)
Hello,
I don't know if anybody can help me, because I've search a lot without success.
On my DOS Terminal (XP) I send successfully those commands :
doskey CS=call smile.bat $*
CS
or
CS arg1
It works PERFECTLY !
Then I insert these commands in a new batch file :
#echo off
doskey CS=call smile.bat $*
CS arg1
Error returned : CS is an unknown command...
I do absolutely want to use aliases in my batch program, but I do not want to modify my Path nor my Reg, because it is just to use in the Batch itself. I want to find a solution, but I need any idea. Please if some one can help me with an example, it would be very useful.
EDIT
You cannot run a doskey macro from a batch program.
If you just want to call a Batch file via another name, then just define another Batch file (with the second name) that call the first one. For example
CS.bat file may have this line:
#call smile.bat %*
then, in the first Batch file:
call CS
or
call CS arg1
If this is enough for you, then you may even create the alias Batch file inside the first Batch file this way:
echo #call smile.bat %%*> CS.bat
I hope it helps...