Pro*C unable to read parameter passing from korn shell script - shell

I have a korn shell script which will pass 4 parameters to a Pro*C file
The syntax of the korn shell script are below:
### $command_dir/proc_file_name / $deptid $txdate $pid
### I hardcode the values for testing
$command_dir/proc_file_name / 701 20170109 201701094444001
The syntax of the Pro*C file:
....
main(argc, argv)
int argc
char *argv[];
username.len=strlen(argv[1]);
strncpy((char*)username.arr, argv[1],username.len);
username.arr[username.len]='\0';
deptid.len=strlen(argv[1]);
strncpy((char*)deptid.arr, argv[1],deptid.len);
deptid.arr[deptid.len]='\0';
txdate.len=strlen(argv[1]);
strncpy((char*)txdate.arr, argv[1],txdate.len);
txdate.arr[txdate.len]='\0';
pid=atoi(argv[4]);
printf("\n%s\n", username);
printf("\n%d\n", deptid);
printf("\n%d\n", txdate);
printf("\n%d\n", pid);
....
I found that the values of the parameters were not I put.
Please help...
Many Many thanks

You are using the same array index of 1 for username, deptid, and txdate. Correct that and you would be good.
Accessing argv[1] etc., without checking argc isn't a good practice. When invoked without arguments, your code will result in a core dump.
Also, I don't think your code has the right syntax. Can you please paste the code that compiles?

Related

Workaround for Scala Error: The command line is too long?

I'm trying to compile someone's mod of minecraft so that I can make some changes to it. It uses scala somewhere in the recompiling, and I get this error:
== ERRORS FOUND in SCALA CODE ==
The command line is too long.
================================
I tend to agree:
'"scalac.bat" -encoding UTF-8 -deprecation -target:jvm-1.6 -classpath "jars\vers
ions\1.8.1\1.8.1.jar;lib;lib\*;lib;lib\*;jars\bin\minecraft.jar;jars\bin\jinput.
jar;jars\bin\lwjgl.jar;jars\bin\lwjgl_util.jar;jars\libraries\net\java\jinput\ji
nput\2.0.5\jinput-2.0.5.jar;jars\libraries\org\lwjgl\lwjgl\lwjgl-platform\2.9.1\
lwjgl-platform-2.9.1-natives-windows.jar;jars\libraries\com\ibm\icu\icu4j-core-m
ojang\51.2\icu4j-core-mojang-51.2.jar;jars\libraries\tv\twitch\twitch-external-p
latform\4.5\twitch-external-platform-4.5-natives-windows-64.jar;jars\libraries\c
om\sixense\SixenseJavaLibrary\062612.0\SixenseJavaLibrary-062612.0-natives-windo
ws.jar;jars\libraries\org\apache\httpcomponents\httpcore\4.3.2\httpcore-4.3.2.ja
r;jars\libraries\org\apache\logging\log4j\log4j-api\2.0-beta9\log4j-api-2.0-beta
9.jar;jars\libraries\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.
jar;jars\libraries\net\java\jutils\jutils\1.0.0\jutils-1.0.0.jar;jars\libraries\
com\paulscode\libraryjavasound\20101123\libraryjavasound-20101123.jar;jars\libra
ries\net\sf\jopt-simple\jopt-simple\4.6\jopt-simple-4.6.jar;jars\libraries\com\g
oogle\guava\guava\17.0\guava-17.0.jar;jars\libraries\commons-logging\commons-log
ging\1.1.3\commons-logging-1.1.3.jar;jars\libraries\org\apache\commons\commons-c
ompress\1.8.1\commons-compress-1.8.1.jar;jars\libraries\com\sixense\SixenseJava\
062612.1\SixenseJava-062612.1.jar;jars\libraries\tv\twitch\twitch\6.5\twitch-6.5
.jar;jars\libraries\com\paulscode\codecjorbis\20101023\codecjorbis-20101023.jar;
jars\libraries\optifine\OptiFine\1.8.1_HD_U_B2\OptiFine-1.8.1_HD_U_B2.jar;jars\l
ibraries\com\paulscode\soundsystem\20120107\soundsystem-20120107.jar;jars\librar
ies\org\json\json\20140107\json-20140107.jar;jars\libraries\com\paulscode\librar
ylwjglopenal\20100824\librarylwjglopenal-20100824.jar;jars\libraries\org\lwjgl\l
wjgl\lwjgl_util\2.9.1\lwjgl_util-2.9.1.jar;jars\libraries\commons-codec\commons-
codec\1.9\commons-codec-1.9.jar;jars\libraries\org\apache\httpcomponents\httpcli
ent\4.3.3\httpclient-4.3.3.jar;jars\libraries\de\fruitfly\ovr\JRiftLibrary\0.4.4
.1\JRiftLibrary-0.4.4.1-natives-windows.jar;jars\libraries\org\lwjgl\lwjgl\lwjgl
\2.9.1\lwjgl-2.9.1.jar;jars\libraries\commons-io\commons-io\2.4\commons-io-2.4.j
ar;jars\libraries\com\mojang\realms\1.7.4\realms-1.7.4.jar;jars\libraries\net\ai
b42\mumblelink\JMumbleLibrary\1.1\JMumbleLibrary-1.1-natives-windows.jar;jars\li
braries\com\mojang\authlib\1.5.17\authlib-1.5.17.jar;jars\libraries\com\google\c
ode\gson\gson\2.2.4\gson-2.2.4.jar;jars\libraries\net\minecraft\launchwrapper\1.
7\launchwrapper-1.7.jar;jars\libraries\com\paulscode\codecwav\20101023\codecwav-
20101023.jar;jars\libraries\tv\twitch\twitch-platform\6.5\twitch-platform-6.5-na
tives-windows-64.jar;jars\libraries\net\java\jinput\jinput-platform\2.0.5\jinput
-platform-2.0.5-natives-windows.jar;jars\libraries\de\fruitfly\ovr\JRift\0.4.4.1
\JRift-0.4.4.1.jar;jars\libraries\org\apache\logging\log4j\log4j-core\2.0-beta9\
log4j-core-2.0-beta9.jar;jars\libraries\net\aib42\mumblelink\JMumble\1.0\JMumble
-1.0.jar;jars\libraries\io\netty\netty-all\4.0.23.Final\netty-all-4.0.23.Final.j
ar" -sourcepath src\minecraft -d bin\minecraft src\minecraft\*.java src\minecraf
t\net\minecraft\block\*.java src\minecraft\net\minecraft\block\material\*.java s
rc\minecraft\net\minecraft\block\properties\*.java src\minecraft\net\minecraft\b
lock\state\*.java src\minecraft\net\minecraft\block\state\pattern\*.java src\min
ecraft\net\minecraft\client\*.java src\minecraft\net\minecraft\client\audio\*.ja
va src\minecraft\net\minecraft\client\entity\*.java src\minecraft\net\minecraft\
client\gui\*.java src\minecraft\net\minecraft\client\gui\achievement\*.java src\
minecraft\net\minecraft\client\gui\inventory\*.java src\minecraft\net\minecraft\
client\gui\spectator\*.java src\minecraft\net\minecraft\client\gui\spectator\cat
egories\*.java src\minecraft\net\minecraft\client\gui\stream\*.java src\minecraf
t\net\minecraft\client\main\*.java src\minecraft\net\minecraft\client\model\*.ja
va src\minecraft\net\minecraft\client\multiplayer\*.java src\minecraft\net\minec
raft\client\network\*.java src\minecraft\net\minecraft\client\particle\*.java sr
c\minecraft\net\minecraft\client\player\inventory\*.java src\minecraft\net\minec
raft\client\renderer\*.java src\minecraft\net\minecraft\client\renderer\block\mo
del\*.java src\minecraft\net\minecraft\client\renderer\block\statemap\*.java src
\minecraft\net\minecraft\client\renderer\chunk\*.java src\minecraft\net\minecraf
t\client\renderer\culling\*.java src\minecraft\net\minecraft\client\renderer\ent
ity\*.java src\minecraft\net\minecraft\client\renderer\entity\layers\*.java src\
minecraft\net\minecraft\client\renderer\texture\*.java src\minecraft\net\minecra
ft\client\renderer\tileentity\*.java src\minecraft\net\minecraft\client\renderer
\vertex\*.java src\minecraft\net\minecraft\client\resources\*.java src\minecraft
\net\minecraft\client\resources\data\*.java src\minecraft\net\minecraft\client\r
esources\model\*.java src\minecraft\net\minecraft\client\settings\*.java src\min
ecraft\net\minecraft\client\shader\*.java src\minecraft\net\minecraft\client\str
eam\*.java src\minecraft\net\minecraft\client\util\*.java src\minecraft\net\mine
craft\command\*.java src\minecraft\net\minecraft\command\common\*.java src\minec
raft\net\minecraft\command\server\*.java src\minecraft\net\minecraft\crash\*.jav
a src\minecraft\net\minecraft\creativetab\*.java src\minecraft\net\minecraft\dis
penser\*.java src\minecraft\net\minecraft\enchantment\*.java src\minecraft\net\m
inecraft\entity\*.java src\minecraft\net\minecraft\entity\ai\*.java src\minecraf
t\net\minecraft\entity\ai\attributes\*.java src\minecraft\net\minecraft\entity\b
oss\*.java src\minecraft\net\minecraft\entity\effect\*.java src\minecraft\net\mi
necraft\entity\item\*.java src\minecraft\net\minecraft\entity\monster\*.java src
\minecraft\net\minecraft\entity\passive\*.java src\minecraft\net\minecraft\entit
y\player\*.java src\minecraft\net\minecraft\entity\projectile\*.java src\minecra
ft\net\minecraft\event\*.java src\minecraft\net\minecraft\init\*.java src\minecr
aft\net\minecraft\inventory\*.java src\minecraft\net\minecraft\item\*.java src\m
inecraft\net\minecraft\item\crafting\*.java src\minecraft\net\minecraft\nbt\*.ja
va src\minecraft\net\minecraft\network\*.java src\minecraft\net\minecraft\networ
k\handshake\*.java src\minecraft\net\minecraft\network\handshake\client\*.java s
rc\minecraft\net\minecraft\network\login\*.java src\minecraft\net\minecraft\netw
ork\login\client\*.java src\minecraft\net\minecraft\network\login\server\*.java
src\minecraft\net\minecraft\network\play\*.java src\minecraft\net\minecraft\netw
ork\play\client\*.java src\minecraft\net\minecraft\network\play\server\*.java sr
c\minecraft\net\minecraft\network\status\*.java src\minecraft\net\minecraft\netw
ork\status\client\*.java src\minecraft\net\minecraft\network\status\server\*.jav
a src\minecraft\net\minecraft\pathfinding\*.java src\minecraft\net\minecraft\pot
ion\*.java src\minecraft\net\minecraft\profiler\*.java src\minecraft\net\minecra
ft\realms\*.java src\minecraft\net\minecraft\scoreboard\*.java src\minecraft\net
\minecraft\server\*.java src\minecraft\net\minecraft\server\gui\*.java src\minec
raft\net\minecraft\server\integrated\*.java src\minecraft\net\minecraft\server\m
anagement\*.java src\minecraft\net\minecraft\server\network\*.java src\minecraft
\net\minecraft\src\*.java src\minecraft\net\minecraft\stats\*.java src\minecraft
\net\minecraft\tileentity\*.java src\minecraft\net\minecraft\util\*.java src\min
ecraft\net\minecraft\village\*.java src\minecraft\net\minecraft\world\*.java src
\minecraft\net\minecraft\world\biome\*.java src\minecraft\net\minecraft\world\bo
rder\*.java src\minecraft\net\minecraft\world\chunk\*.java src\minecraft\net\min
ecraft\world\chunk\storage\*.java src\minecraft\net\minecraft\world\demo\*.java
src\minecraft\net\minecraft\world\gen\*.java src\minecraft\net\minecraft\world\g
en\feature\*.java src\minecraft\net\minecraft\world\gen\layer\*.java src\minecra
ft\net\minecraft\world\gen\structure\*.java src\minecraft\net\minecraft\world\pa
thfinder\*.java src\minecraft\net\minecraft\world\storage\*.java src\minecraft\o
ptifine\*.java src\minecraft\optifine\json\*.java' failed : 1
Given that windows has a character limit on the command line.
I'm using windows 8.1 and scala 2.11.0.
I was wondering, is there a way to set this as an environment/path variable or something to avoid this?
What would I have to change? I'm very new to messing around with system stuff like this, but I think I know where scala is called in the scripts and this argument is given. If that helps.
scalac accepts an #file parameter containing a file with arguments in. So if you can modify whatever script is calling scalac.bat to instead put the arguments in a temporary file arguments.txt and then call scalac #arguments.txt that should work.

Reading and Writing File Contents From HTTP Post Data In Bash

Problem Statement:
I am trying to upload a file through an HTML form using an HTTP post request and then write it to a file called configuration.xml on my local server. I can only use the stock capabilities of the server, so, as much as I'd love to, I can't use cURL, PHP, Perl, or anything that I'd have to install on the server. What I have tried doing is having the HTML form open a CGI file as the form action and all this CGI file does is run the Bash script with the proper HTML formatting. I would run the Bash script directly from the HTML form, but my research led me to believe that this isn't possible without having to edit .htaccess or other hacky alternatives, which are not roads I want to go down. (If this can be done in a reasonable fashion, please enlighten me!) Regardless, I am able to successfully run the Bash script. I know this because I put a "touch configuration.xml" command in the script and it creates it every time. My script is also able to tell that it is an HTTP Post, as shown by the echoed text in the browser, but then I can't seem to be able to properly read any data from the file. I tried echoing the data as well as redirecting the read data to a file, but nothing appeared in the browser and nothing wrote to the file I specified. This very well may be me not knowing Bash scripting well enough or something silly like that, but I really don't know how to proceed from here.
Code:
UploadToServer.html:
<form action="run_script.cgi" method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit" value="Submit">
</form>
run_script.c:
Note: I compile this to a CGI file with the following command: gcc run_script.c -o run_script.cgi
#include <stdlib.h>
#include <stdio.h>
int main() {
system("./test.sh &");
printf("Content-Type: text/html\r\n\r\n");
printf(""); // print blank line for proper HTML header formatting
printf("<html>\n");
printf("</HTML>\n");
}
test.sh:
The non-commented code in the second if statement is from here. The commented code is from here.
#!/bin/bash
touch configuration.xml
if [[ $REQUEST_METHOD = 'POST' ]]; then
echo "this is a post!"
if [ "$CONTENT_LENGTH" -gt 0 ]; then
echo "entered second if statement!"
# read -n $CONTENT_LENGTH POST_DATA <&0
# echo "$CONTENT_LENGTH"
while read line
do eval "echo ${line}"
done
fi
fi
I also tried the approach in the third code block of this post, but didn't get any output. I also looked through this post, but it doesn't seem to grab all the data from the file like I need to. I also tried the approach of just using a CGI file like suggested in this post (_http://blog.purplepixie.org/2013/08/cc-cgi-file-upload/), but, once again, no output. I've been looking through the Apache error log as I try new things and no errors come up.
Anybody have any ideas on what I could possibly be doing wrong? Is there a different approach worth looking into? Any suggestions are greatly appreciated!
I figured out how to do it, with some help from my friends. I ended up doing it all in a CGI script and foregoing the Bash component. While this isn't what I asked for in my original question, it gets the job done for me, which is really what the question was asking.
The following is the C code I'm now using to successfully write the file on the server:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void print_empty_html_page();
int main() {
char * req_method_str = getenv("REQUEST_METHOD");
if (req_method_str != NULL) {
if (strcmp(req_method_str, "POST") == 0) {
// process POST arguments
char * len_str = getenv("CONTENT_LENGTH");
if (len_str != NULL) {
int len = atoi(len_str);
if (len > 0) {
FILE * fp;
fp = fopen("file.xml", "w");
char * postdata = malloc((len + 1) * sizeof(char));
fread(postdata, sizeof(char), len, stdin);
postdata[len] = '\0';
fprintf(fp, "%s\n", postdata);
free(postdata);
fclose(fp);
}
system("sed -e '/Content/d' -e '/[-][-][*][*][*][*][*]/d' -e '/^[s]*$/d' -e '/WebKitFormBoundary/d' -e '/Submit/d' < file.xml > file_trimmed.xml");
system("rm file.xml");
}
}
}
print_empty_html_page();
return 0;
}
void print_empty_html_page() {
// Send the content type, letting the browser know this is HTML
printf("Content-type: text/html\r\n\r\n");
// Header information that prevents browser from caching
printf(
"<META HTTP-EQUIV=\"CACHE-CONTROL\" CONTENT=\"NO-CACHE, NO-STORE\">\r\n\r\n");
// Top of the page
printf("<html>\n");
printf("<BODY>\n");
// Finish up the page
printf("</BODY></html>\n");
}
Note: This method writes the entire HTTP POST to the file 'file.xml'. The system call to 'sed' is to remove the tags from the HTTP POST that don't correspond to the actual data in the file that was uploaded. If you need to check for additional unwanted lines, just add another -e '/<line_with_expression_to_delete>/d' in that sed call, where line_with_expression_to_delete is the expression you want to match and then delete all lines containing that expression. I couldn't figure out how to delete all the blank lines in the newly uploaded file, even though '/^[s]*$/d' should do that, according to my research. Gonna have to look into that more...
Also note: This method only works for uploading text files. It does not work for other file types, such as JPEGs or OGGs.
Hopefully this helps some other people with the same problem. Let me know if you have any questions.

Invalid command name in Tcl when using format

I'm running the following commands
set full_pin_name [format "%s %s" $top_cell $encoded_name]
puts "full_pin_name is $full_pin_name"
and I get the following error:
full_pin_name is invalid command name "A" B
when top_cell equals A and encoded_name equals B.
Why is this happening?
I suspect the problem is with your $top_cell variable, which has the value invalid command name "A". To check, try the following line before your format line:
puts ">$top_cell<"
If indeed, $top_cell value has a problem, you can then trace back to the last set command. Let us know if it fixes your problem, or we might try some other approaches.
Try repeating this in a plain Tcl shell, it works. Something is different in your Tcl shell.
Try
info body set
and
info body format
If either report something other than set isn't a procedure or format isn't a procedure then you have your culprit.
May be this code runs in a namespace which has the set command defined in it?
To demonstrate:
% namespace eval foo {
proc set args {
puts hey!
}
proc whatever {top_cell encoded_name} {
set full_pin_name [format "%s %s" $top_cell $encoded_name]
puts "full_pin_name is $full_pin_name"
}
}
% ::foo::whatever A B
hey!
can't read "full_pin_name": no such variable
%
As far as I can tell without a TCL interpreter here it should work assuming a normal interpreter with format defined. so it looks like maybe format has been renamed or doesn't exist as a command in the interpreter you are using?
To get you going you don't really need format to join strings anyway
set fill_pin_name "$top_cell $encoded_name"
should so what you need
Maybe your code looks like this:
set encoded_name B
if { [catch {[A]} top_cell]} {
set full_pin_name [format "%s %s" $top_cell $encoded_name]
puts "full_pin_name is $full_pin_name"
}
The result is:
full_pin_name is invalid command name "A" B

command line arguments in bash to Rscript

I have a bash script that creates a csv file and an R file that creates graphs from that.
At the end of the bash script I call Rscript Graphs.R 10
The response I get is as follows:
Error in is.vector(X) : subscript out of bounds
Calls: print ... <Anonymous> -> lapply -> FUN -> lapply -> is.vector
Execution halted
The first few lines of my Graphs.R are:
#!/bin/Rscript
args <- commandArgs(TRUE)
CorrAns = args[1]
No idea what I am doing wrong? The advice on the net appears to me to say that this should work. Its very hard to make sense of commandArgs
With the following in args.R
print(commandArgs(TRUE)[1])
and the following in args.sh
Rscript args.R 10
I get the following output from bash args.sh
[1] "10"
and no error. If necessary, convert to a numberic type using as.numeric(commandArgs(TRUE)[1]).
Just a guess, perhaps you need to convert CorrAns from character to numeric, since Value section of ?CommandArgs says:
A character vector containing the name
of the executable and the
user-supplied command line arguments.
UPDATE: It could be as easy as:
#!/bin/Rscript
args <- commandArgs(TRUE)
(CorrAns = args[1])
(CorrAns = as.numeric(args[1]))
Reading the docs, it seems you might need to remove the TRUE from the call to commandArgs() as you don't call the script with --args. Either that, or you need to call Rscript Graphs.R --args 10.
Usage
commandArgs(trailingOnly = FALSE)
Arguments
trailingOnly logical. Should only
arguments after --args be returned?
Rscript args.R 10 where 10 is the numeric value we want to pass to the R script.
print(as.numeric(commandArgs(TRUE)[1]) prints out the value which can then be assigned to a variable.

Bash evironment variables cannot have values starting from a digit?

I have an environment variable in bash and want to set its value to a string starting from a digit.
But in the shell you have to create the variables, and then export them so they go to the environment. Is there a way to put some value into shell's environment without touching variables, or maybe create a variable whose value starts with a digit?
The only way I could think of was by starting a new shell using env:
env 0FOO=BAR /usr/bin/bash
I tried this under Cygwin and it seemed to work.
The only valid beginning character types for bash variables are letters and underscores.
Why do you want to do this? You can do:
export _1="some value"
or
export a1="some value"
The reason that you can't do what you're asking is that a variable like "$1" would be confused with the positional parameter $1.
The processing required is fiddly and tedious and not dreadfully sensible, but (in outline, error checks on malloc() omitted):
char **env = environ;
while (*env != 0)
*env++;
char **newenv = malloc((env - environ + 1) * sizeof(*newenv));
memcpy(newenv, environ, (env - environ) * sizeof(char *));
newenv[env - environ] = "386=pygmalion";
newenv[env - environ + 1] = 0;
char *args[] = { "modded-env-bash", 0 };
execve("/bin/bash", args, newenv);
exit(1);

Resources