LEARN SQL THE HARD WAY - Continued Troubles with creating .db from .sql with sqlite3 - powershell

Thanks for taking the time to read this. I'm a beginner programmer with some experience in Python, and I just started reading Zed Shaw's Learn SQL the Hard Way. In exercise 1, he has you create an .sql file type the following command in powershell:
sqlite3 ex1.db < ex1.sql
After running the following in the command-line, I receive the following error message
The '<' operator is reserved for future use.
I checked a few stackoverflow pages for answers.
Unfortunately, I cannot figure out how to bypass this error message and make a .db file from a .sql file. Apologies for any nuisances; I'm very new to stackoverflow. Any help or advice in solving this problem is greatly appreciated!

The examples that you are looking at are running inside of the bash shell on a *NIX platform. You stated that you're using PowerShell which means that the command will be different. I'm guessing it will look something like:
Get-Content ex1.sql | sqlite3 ex1.db

PowerShell is incompatible with any other shell.
If you do not know the syntax of both normal shells and PowerShell, and how to translate from one to the other, you should not user PowerShell in the first place.
Use the standard Windows command prompt (cmd.exe) instead.

Related

Reading user's PS1 from Swift command-line tool

Is it possible to extract the user's PS1 from the environment in a Swift script, so that I can replicate their prompt?
I left a note for myself a few years ago saying that it "disappears from the environment in the context of the script", but I figured it would be useful to ask.
(I'm aware that this question won't necessarily work between shells, but assume that I only care about bash. Furthermore, I know I can't necessarily interpret everything in a user's prompt, but I would like to get it).
Try this in Swift script :
bash -i -c 'echo "$PS1"'

How do i run/import a downloaded command-line programm?

there is a command-line program called tcpvcon.exe
According to Microsofts website (https://learn.microsoft.com/en-us/sysinternals/downloads/tcpview) it should be possible to access it the following way:
tcpvcon [-a] [-c] [-n] [process name or PID]
Do I have to import this executable somehow to be able to access its commands?
I am trying to write a small script, but I am struggling to access the program in a reasonable way that allows me to pass it arguments.
I am using Powershell.
Thanks
Edit:
I downloaded the program, executed it once and accepted the licence agreement. Now I would like to be able to use the above command in Powershell.
If I use it i get following error:
"tcpvcon" is not recognized as the name of a cmdlet...
Do I have to import the cmdlet somhow? I cannot find any information on this... It is probably a very simple fix and I just do not know the procedure.
Thanks again.

'powershell.exeA' is not recognized as an internal or external command,

I am running into a bit of a problem when attempting to use Powershell with NRPE. Now I ran this command,
command[alias_check_commerce_log]=cmd /c echo C:\Program Files\nrpe\plugins\file_checker.ps1; exit($LastExitCode) | powershell.exe -command -
in cmd and it went through without a hitch. Just when I call it via Icinga, for some odd reason, it spits out 'powershell.exeA' is not recognized as an internal or external command. Now I know the A is not supposed to be sitting with powershell.exe, so how would I keep this from happening? Keep in mind that the command is the same in the config as posted here. Checked all text in hopes of it just being a simple Typo. I just can't seem to wrap my head around this one and figure out how to keep this from happening. Any and all help is appreciated, thank you.
Probably file encoding. You likely copy/pasted the command line from a web site or something, and there is a special character after .exe.
Open the file where that command is defined in an editor that supports different encodings and hopefully one that can show whitespace and "special" characters, and inspect the file.
Or Start over and manually type the commands.

Execute batch file using dos()

I got a problem when executing batch file commands through matlab. This batch file includes commands to run simulations in Adams. When I execute the batch file directly from DOS window, it works well. But if I use matlab to execute it (using command dos()), it gives error saying 'cannot check out the license for Adams'.
This confuses me: if the license is incorrect, it should not work no matter I execute the batch file directly in DOS or ask MATLAB to execute it. I also tried to execute other DOS commands through matlab using dos() and it worked well.
Does anyone know what the problem may be?
Such issues are commonly caused by some environment variables being changed or cleared by MATLAB. I have very similar experience on Linux and Mac OS X, where this causes havoc when using system or unix.
In Unix-like systems, MATLAB is started from a shell script where all of this happens. So you can either incorporate missing variables there or in the .matlab7rc.sh in your home directory (the latter is preserved when you upgrade MATLAB and it is much easier to use). I won't go into all the Unix details here.
An alternative workaround is to explicitly set those variables when you issue a system command (e.g. system('export variable=value ; ...')). It is quite a bit of work, but you can then use that MATLAB code on different computers with ease.
On Windows, I'm not completely sure about the exact location of the corresponding files (and whether MATLAB starts in quite a similar way as on Unix). But if they exist, you can probably find it in the MATLAB documentation.
Anyhow, the alternative fix should work here as well.
First you need to diagnose which system variables you need (likely a PATH or anything that has a name related to Adams).
To do so in Windows, run set from the Windows command prompt (cmd.exe) and from within MATLAB. Whatever differs in the output is a possible suspect for your problem.
To inspect just a single variable, you can use the command echo %variablename%.
I will assume that you have found that the suspect environment variable is missing and should be set to value.
The workaround fix is then to run your command in MATLAB as system('set suspect=value & ...') where you replace ... with your original command.

powershell/sqlplus error SP2-0042: unknown command " ■#" - rest of line ignored

I am running this command in powershell:
sqlplus system/passwd#mydb #my_sql
I have tried it with and without backticks and various other versions I found via Google. I keep getting an error when the command is passed off to sqlplus and have been unsucessful in finding the fix. Hopefully someone here can help out?
The error I get is:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SP2-0042: unknown command " ■#" - rest of line ignored.
So I am sucessfully connecting to the database but there is an extra character being passed to sqlplus in front of the '#'. " ■#" in notepad++ looks like " ¦#"
If you created your SQL command file using a redirect (> or >>) in powershell - like:
myProgram > mySQL.out
and then run it like:
&sqlplus mypw/myuser#mydb.xyz.com "#mySQL.out"
Powershell may have saved the output file in UTF-16 format, which Sqlplus does not like.
(You can confirm by creating the exact same file by hand and then comparing it - byte count will be off and in KDiff you'll get message to the effect that the text is equal, but the files are not binary equal).
To fix - you need to do two things: :
Add some blank lines to the top of your SQL commands - Powershell will still write a BOM (Byte Order Mark) there and it looks like it's pretty hard to get it to avoid that - but sqlplus will just go by it, albeit giving an error - but will move on to the rest of your code OK.
And then run this command in powershell before creating your file: $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
See Changing PowerShell's default output encoding to UTF-8
I received this error:
SP2-0042: unknown command " ■S" - rest of line ignored.
and this fixed that - or at least I was able to run it. You can also just cut and past it from one window into another using Notepad++ and that will solve the BOM and encoding issue.
Update Problem Solved. This turned out being "not seeing the trees through the forest". I have been using these sql scripts for several years without issue called from a bash script. When I tried converting the bash script to powershell and ran into issues I blamed it on powershell. However; it turned out there was something corrupt in the sql file itself. There were no obvious errors when looking at the file in notepad++ even with show all symbols clicked and it was ANSI format. I determined it was the sql file itself when I manually ran sqlplus from a cmd window I still had the same error I was getting with powershell. I rewrote the script and saved it and the problem was fixed. I should have manually ran the script on day one and I probably could have resolved sooner.
I had the same problem. My issue was caused because the script file was saved as unicode. I don't know if this will help you or not, but here is how I fixed it:
Edit the script with notepad. Click File -> Save As. Change type from Unicode (or whatever) to ANSI, and save.
A couple of suggestions
Try the invoke operator:
&sqlplus system/passwd#mydb #my_sql
Try start-process:
start-process -NoNewWindow -FilePath sqlplus -ArgumentList #"
system/passwd#mydb #my_sql
"#
I had typical problem. The message was:
unknown command "and" - rest of line ignored.
The reason was an empty string in code.
e.g.
select ...
from ...
where ...
[empty string]
and ... < here was an error message
use as following
sqlplus -s system/passwd#mydb "#my_sql";