Mixing TCC and linux

May 20, 2008
10,623
81
Syracuse, NY, USA
On Win7/32, I did something similar with Gnu utils. I doubt there are 64-bit versions of them, so I now have this on Win10/64. It'll probably get spruced up, but it demonstrates how seamless mixing linux and tcc can be.
Code:
v:\> alias tl
(tasklist |! egrep -v "Total|processes|^$" |! sort -f -b --key=2,2 |! tee %temp\tl.tmp & echo ----
  %@lines[%temp\tl.tmp] & del /q %temp\tl.tmp)
That looks innocent enough, but behind the scenes:
Code:
v:\> alias egrep
wsl egrep

v:\> alias sort
wsl sort
Sample output (got with "tl > clip:", snipped):
Code:
2100  aesm_service   
7872  ApplicationFrameHost
3112  armsvc         
3684  BTDevMgr       
  396  conhost        
3344  conhost        
  628  csrss          
4392  csrss          
*************************snip**********************
8784  svchost        
    4  System         
5384  taskhostw         Task Host Window
5076* tcc               [5076]  v:\
  720  wininit        
4468  winlogon       
3320  wlanext        
8332  WmiPrvSE       
  976  WUDFHost       
    0  [System Process]
----
  142
That made me wonder if I can display head and tail (but not middle) of output instead of manually snipping ... not with anything I can think of.
 
May 20, 2008
10,623
81
Syracuse, NY, USA
Not without a temporary file or custom pipe.
Then custom pipe it is! This (below) works (bulletproof?). It uses TPIPE to get stdout into a file. Can anyone think of a more elegant, internal, and bulletproof way for a library routine, BTM, or alias, knowing it will be used in a pipe, to re-route stdout to a file?
Code:
g:\tc23\library> library /f snip
snip {
set tmpfile=%temp\snip.tmp
tpipe /output=%tmpfile
head /n %1 %tmpfile
echo ***** SNIP *****
tail /n %1 %tmpfile
del /q %tmpfile
unset %tmpfile
}
Code:
g:\tc23\library> dir c:\windows | snip 5

 Volume in drive C is unlabeled    Serial number is b813:1d21
 Directory of  C:\windows\*

2018-09-20  22:39         <DIR>    .
***** SNIP *****
2009-06-10  17:34         316,640  WMSysPr9.prx
2009-07-13  21:14           9,216  write.exe
2009-06-10  17:42             707  _default.pif
           7,498,887 bytes in 36 files and 57 dirs    7,581,696 bytes allocated
       2,010,251,264 bytes free
 
May 20, 2008
10,623
81
Syracuse, NY, USA
Here's a fix.
Code:
g:\tc23\library> library /f snip
snip {
setlocal
set tmpfile=%temp\snip.tmp
tpipe /output=%tmpfile
set lines=%@min[%1,%@eval[(%@lines[%tmpfile]+1)\2]]
head /n %lines %tmpfile
echo ***** SNIP *****
tail /n %lines %tmpfile
del /q %tmpfile
endlocal
}
Code:
g:\tc23\library> echo 1^n2^n3^n4 | snip 25
1
2
***** SNIP *****
3
4

g:\tc23\library> echo 1^n2^n3^n4^n5^n6 | snip 4
1
2
3
***** SNIP *****
4
5
6
 
Aug 3, 2016
376
9
Netherlands
That made me wonder if I can display head and tail (but not middle) of output instead of manually snipping ... not with anything I can think of.
In CMD I use
Code:
dir | (head -5 & tail -2)
So I guess a ls|(head -5 ; tail -2) should work.

(head and tail are both from Cygwin; 64-bit)
 
May 20, 2008
10,623
81
Syracuse, NY, USA
Cool, Maarten! Thanks. It works well with only built-in TCC stuff and a little addition. It works in an in-process pipe (|!) too. But I don't understand HOW it works! ... anyone?
[/code]
g:\tc23\library> (do i=1 to 20 (echo %i)) | (head /n 3 & echo ******** SNIP ******** & tail /n 6)
1
2
3
******** SNIP ********
15
16
17
18
19
20
[/code]

Do you know how to do the same thing NOT in a pipe, but to a file?
Code:
same_thing filename
 
May 20, 2008
10,623
81
Syracuse, NY, USA
Even something as bizarre as this works!
Code:
g:\tc23\library> (do i=1 to 20 (echo %i)) |! (head /n 3 | wc & echo ******** SNIP ******** & tail /n 6 | wc)
  Lines   Words   Chars
      3       3       9
******** SNIP ********
  Lines   Words   Chars
      6       6      24
 
May 20, 2008
10,623
81
Syracuse, NY, USA
Aha! Trying the other order [command | (tail & head)] (which doesn't work) explains how it works. When head is finished, there's still more STDOUT to go to the subsequent commands.
 

samintz

Scott Mintz
May 20, 2008
1,421
13
Solon, OH, USA
Do you happen to know if you launch a process with wsl if any processes launched by that will automatically be run in WSL?
 
May 20, 2008
10,623
81
Syracuse, NY, USA
Do you happen to know if you launch a process with wsl if any processes launched by that will automatically be run in WSL?
I think it depends on what the wsl-launched process launches. If it starts a Linux program I suppose it runs in wsl. If it starts a Wimdows program, I suppose not. Inside wsl, you can see both file systems. After all the Linus directories in bash's (default) path are the directories in the Windows path, for example, /mnt/c/Windows/System32. to get a Windows program ".exe" is necessary. So, in bash, "notepad.exe" will start Notepad because it's on the path. If, in bash, I issue "/mnt/c/apps/tc23/tcc.exe" I get TCC in the same console, just like starting another command interpreter while in TCC. It's all pretty transparent.
 

samintz

Scott Mintz
May 20, 2008
1,421
13
Solon, OH, USA
We have a new-ish build environment that runs in Linux. Currently we're using Docker and running Linux in a VM. I just wondered if we could run the builds from WSL instead. Once setup it's all pretty transparent. I run bash in a TCMD tab. And I can start the session from a toolbar button.

But I am not a fan of bash. The scripting language is pretty nice, but TCC has spoiled me for directory navigation. So it would be pretty awesome if I could stay in Windows but invoke WSL to do the build.
 
May 20, 2008
10,623
81
Syracuse, NY, USA
I dunno. I'n no fan of bash either. Though I've forgotten almost everything, I've done extensive scripting in tcsh/csh. A tcsh package is available for Ubuntu and when I figure out how to install it on the WSL set-up, I will do so. Any tips on doing that would be appreciated.
 
May 20, 2008
10,623
81
Syracuse, NY, USA
It's been 20+ years since I've used Linux and things have gotten a lot easier. After a bit of googling, installing tcsh was trivial.

Code:
sudo apt update
sudu apt install tcsh
I played with tcsh.exe for a while and had a %home directory on this computer. Sadly, I threw it all out. I wish I still had my .tcshrc, .aliasrc (?), and .lessrc (maybe others). They'd surely jog memory and make it easier to make things as I (used to) like them.
 
Thread starter Similar threads Forum Replies Date
Joe Caverly T&T - Aliases 7
Joe Caverly T&T - Aliases 0