-1

A csh script that takes 2 arguments is executed using system() call from a JNI C++ function as follows:

int ret = system("abc.csh C:\tmp\file.tmp $VAR_NAME");  
  • When run on Sun, the script executes properly accepts both arguments and writes value of $VAR_NAME inside C:\tmp\file.tmp

  • But when run on Windows the abc.csh opens up in default text editor Notepad.

What should be done to make the script execute same way on Windows too?

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Amit
  • 29
  • Probably, because `.csh` isn't known file extension on windows? Shell scripts on windows, typically are in `.bat`, or `.cmd` files. – Algirdas Preidžius May 31 '17 at 09:27
  • You can't just run cshell scripts on Windows - Windows doesn't come with that shell, and most likely; the commands that shell script then tries to run won't be available on Windows either. – Jesper Juhl May 31 '17 at 09:46
  • To quote Larry Wall: "It is easier to port a shell than to port a shell script". In other words, you probably can't just run this on Windows without modifications. – Martin Tournoij May 31 '17 at 10:20

1 Answers1

0

This system call rely on your OS for opening the scripts.

On unix, if the script is executable, the OS will know how to execute it (using the bang to determine what interpreter to use).

Windows on the other doesn't know how to execute csh scripts. Instead of trying to execute an executable script (like Sun do), it open the script as an usual text file: with notepad (or whatever text editor is configured for opening text file).

If you want to make your script executable on windows, you have to install a csh shell and associate it with .csh file so that when opening csh script windows will use the shell.

An other solution is to explicitly use the shell with something like this: system("csh abc.csh ...") (which still require to have csh installed on your system)

nefas
  • 1,120
  • 7
  • 16
  • The command inside the system() call, if issued on command line e.g. abc.csh C:\tmp\file.tmp $VAR_NAME will use expanded $VAR_NAME inside abc.csh. i.e. its value will be used. However when called via the program (invoked from same shell as above) as int ret = system("csh abc.csh C:\tmp\file.tmp $VAR_NAME"); it will use only the $VAR_NAME text (without expansion to actual value) Any clue how to get it expand to its actual value even in the program. (Like before, on Sun it expands to its actual value even in the program) – Amit Jun 01 '17 at 12:28